Skip to content

[dotnet-sdk-8.0.100-preview.7.23374.6] Fail to retarget greenshot app to .NET 8.0 with 'MethodInvoker' ambiguous reference exception between 'System.Windows.Forms.MethodInvoker' and 'System.Reflection.MethodInvoker' #9586

@Junjun-zhao

Description

@Junjun-zhao

Application Name: greenshot
OS: Windows 10 21H2
CPU: X64
.NET Build Number: dotnet-sdk-8.0.100-preview.7.23374.6
App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1860865

App github link: https://github.com/greenshot/greenshot

Verify Scenarios:
1). Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.7.23376.3: Fail
2). Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.7.23375.2: Fail
3). Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.7.23374.6: Fail
4). Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.7.23371.2: Fail
5). Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.7.23364.32: Pass
6). Windows10 21h2 x64 + dotnet-sdk-8.0.100-preview.6.23330.14: Pass
7). Windows10 21h2 x64 + .net 7.0.306: Pass

Minimal Repro steps (Demo attached):
WinFormsApp1.zip

  1. Create a winform project(SDK versions before 8.0).
  2. Copy the following code to Form1.cs.
using System.Windows.Forms;
using System.Reflection;
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Invoke((MethodInvoker)delegate
            {
            });
        }
    }
}
  1. Build the source.
  2. Build successfully.
  3. Change the TargetFramework to net8.0-windows in the WinFormsApp1.csproj.
  4. Build the source.

Expected Result:

Build successfully.

Actual Result:

Get Following error:

CS0104: 'MethodInvoker' is an amb
iguous reference between 'System.Windows.Forms.MethodInvoker' and 'System.Reflection.MethodInvoker'

Findings:

  1. Removing using System. Reflection can solve the problem.
  2. Change MethodInvoker to System.Windows.Forms.MethodInvoker can solve the problem.

Dotnet info:

.NET SDK:
 Version:   8.0.100-preview.7.23374.6
 Commit:    3819e84d90

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-preview.7.23374.6\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.0-preview.7.23370.6
  Architecture: x64
  Commit:       ebd23467f0
  RID:          win-x64

.NET SDKs installed:
  8.0.100-preview.7.23374.6 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0-preview.7.23371.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0-preview.7.23370.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.0-preview.7.23371.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions