When a new project is created using .NET 6.0.302 (or after the .NET SDK is upgraded to 6.0.302), compilation errors complaining about duplicate definitions are generated.
C:\Test\cswin32new\Microsoft.Windows.CsWin32\Microsoft.Windows.CsWin32.SourceGenerator\Windows.Win32.MONITOR_FROM_FLAGS.g.cs(22,17)
: error CS0101: The namespace 'Windows.Win32.Graphics.Gdi' already contains a definition for 'MONITOR_FROM_FLAGS' [C:\Test\cswin32n
ew\cswin32new_5xwvzd4u_wpftmp.csproj]
C:\Test\cswin32new\Microsoft.Windows.CsWin32\Microsoft.Windows.CsWin32.SourceGenerator\Windows.Win32.PInvoke.User32.g.cs(38,58): er
ror CS0111: Type 'PInvoke' already defines a member called 'MonitorFromWindow' with the same parameter types [C:\Test\cswin32new\cs
win32new_5xwvzd4u_wpftmp.csproj]
...and so on.
Expected behavior
App should continue to build and run as before.
Repro steps
dotnet new wpf
dotnet add package Microsoft.Windows.CsWin32 --prerelease
NativeMethods.txt content:
HWND
MonitorFromWindow
NativeMethods.json content (if present):
Any of your own code that should be shared?
public MainWindow()
{
InitializeComponent();
var helper = new WindowInteropHelper(this);
var hmonitor = Windows.Win32.PInvoke.MonitorFromWindow(
(Windows.Win32.Foundation.HWND)helper.Handle,
Windows.Win32.Graphics.Gdi.MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONULL);
}
C:\Test\cswin32>dotnet sdk check
.NET SDKs:
Version Status
----------------------------------------
6.0.201 Patch 6.0.203 is available.
Try out the newest .NET SDK features with .NET 7.0.100-preview.6.22352.1.
.NET Runtimes:
Name Version Status
--------------------------------------------------------------------------
Microsoft.AspNetCore.App 5.0.15 .NET 5.0 is out of support.
Microsoft.NETCore.App 5.0.15 .NET 5.0 is out of support.
Microsoft.WindowsDesktop.App 5.0.15 .NET 5.0 is out of support.
Microsoft.AspNetCore.App 6.0.3 Patch 6.0.7 is available.
Microsoft.NETCore.App 6.0.3 Patch 6.0.7 is available.
Microsoft.WindowsDesktop.App 6.0.3 Patch 6.0.7 is available.
After (not working):
C:\Test\cswin32>dotnet sdk check
.NET SDKs:
Version Status
----------------------------------------
6.0.201 Patch 6.0.203 is available.
6.0.302 Up to date.
Try out the newest .NET SDK features with .NET 7.0.100-preview.6.22352.1.
.NET Runtimes:
Name Version Status
--------------------------------------------------------------------------
Microsoft.AspNetCore.App 5.0.15 .NET 5.0 is out of support.
Microsoft.NETCore.App 5.0.15 .NET 5.0 is out of support.
Microsoft.WindowsDesktop.App 5.0.15 .NET 5.0 is out of support.
Microsoft.AspNetCore.App 6.0.3 Patch 6.0.7 is available.
Microsoft.NETCore.App 6.0.3 Patch 6.0.7 is available.
Microsoft.WindowsDesktop.App 6.0.3 Patch 6.0.7 is available.
Microsoft.AspNetCore.App 6.0.7 Up to date.
Microsoft.NETCore.App 6.0.7 Up to date.
Microsoft.WindowsDesktop.App 6.0.7 Up to date.
Actual behavior
When a new project is created using .NET 6.0.302 (or after the .NET SDK is upgraded to 6.0.302), compilation errors complaining about duplicate definitions are generated.
...and so on.
Expected behavior
App should continue to build and run as before.
Repro steps
dotnet new wpf dotnet add package Microsoft.Windows.CsWin32 --prerelease
NativeMethods.txt
content:NativeMethods.json
content (if present):Any of your own code that should be shared?
Context
Before (working):
After (not working):