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

Closed

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

Activity

  1. ghost added
    untriagedThe team needs to look at this issue in the next triage
    on Jul 26, 2023
  2. Junjun-zhao commented on Jul 27, 2023

    @Junjun-zhao
    MemberAuthor

    @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.

  3. transferred this issue fromdotnet/sdkon Jul 27, 2023
  4. marcpopMSFT commented on Jul 27, 2023

    @marcpopMSFT
    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

  5. gpetrou commented on Jul 27, 2023

    @gpetrou
    Contributor

    Maybe this happened because of dotnet/runtime#88415?

  6. merriemcgaw commented on Jul 27, 2023

    @merriemcgaw
    Contributor
  7. JeremyKuhne commented on Jul 27, 2023

    @JeremyKuhne
    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() { }
    }
  8. ghost removed
    untriagedThe team needs to look at this issue in the next triage
    on Jul 27, 2023
  9. ghost locked as resolved and limited conversation to collaborators on Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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