You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[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
Create a winform project(SDK versions before 8.0).
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
{
});
}
}
}
Build the source.
Build successfully.
Change the TargetFramework to net8.0-windows in the WinFormsApp1.csproj.
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:
Removing using System. Reflection can solve the problem.
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]
@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.
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
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:
Activity
Junjun-zhao commentedon Jul 27, 2023
@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 commentedon Jul 27, 2023
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 commentedon Jul 27, 2023
Maybe this happened because of dotnet/runtime#88415?
merriemcgaw commentedon Jul 27, 2023
@JeremyKuhne - FYI
JeremyKuhne commentedon Jul 27, 2023
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: