Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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

Closed
Junjun-zhao opened this issue Jul 26, 2023 · 6 comments

Comments

@Junjun-zhao
Copy link
Member

Junjun-zhao commented Jul 26, 2023

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged The team needs to look at this issue in the next triage label Jul 26, 2023
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@Junjun-zhao
Copy link
Member Author

@marcpopMSFT This bug was found in .NET 8 Preview 7 validation, could you please help confirm whether it is a blocker for Preview 7? Please help to move to the right area if this is not correct. Thanks.

@marcpopMSFT marcpopMSFT transferred this issue from dotnet/sdk Jul 27, 2023
@marcpopMSFT
Copy link
Member

Not sure if this is a winforms issue or Roslyn issue related to the upgrade but routing to winforms first as it appears to be a winforms app.
CC @merriemcgaw

@gpetrou
Copy link
Contributor

gpetrou commented Jul 27, 2023

Maybe this happened because of dotnet/runtime#88415?

@merriemcgaw
Copy link
Member

@JeremyKuhne - FYI

@JeremyKuhne
Copy link
Member

This is expected. There is a new public type that has the same name as our existing one. The source needs updated to explicitly say that they want the WinForms one. This can be done by using the full name or adding a using alias to simplify specifying a known type:

using WinFormsMethodInvoker = System.Windows.Forms.MethodInvoker;

namespace MyNameSpace;

internal class MyClass
{
    public void Foo()
    {
        System.Windows.Forms.MethodInvoker invoker1 = Bar;
        WinFormsMethodInvoker invoker2 = Bar;
    }

    public void Bar() { }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants