[NET10][Regression] error CS0012: The type 'IImage' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.Windows.GdiPlus, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Description
In .NET 10 ref/net10.0/System.Private.Windows.GdiPlus.dll was added to the WindowsDesktop pack and is referenced from System.Drawing.Common.dll.
However, System.Drawing.Common.dll is included in both WindowsForms and WPF profiles while System.Private.Windows.GdiPlus.dll is only included for WIndowsForms, causing compile error in WPF projects when specific types from System.Drawing.Common.dll are used.
Reproduction Steps
Add the following code to a WPF project and compile:
var bitmap = new Bitmap(
Expected behavior
No compile errors.
Actual behavior
error CS0012: The type 'IImage' is defined in an assembly that is not referenced.
Regression?
Yes, From .NET 9
Known Workarounds
No response
Impact
No response
Configuration
No response
Other information
No response
Reference: https://github.com/dotnet/dotnet/pull/2839 https://github.com/dotnet/dotnet/pull/3120
- https://github.com/dotnet/wpf/issues/11134
- https://github.com/dotnet/sdk/issues/51173
@jlaanstra I think this issues fixed in https://github.com/dotnet/dotnet/pull/3120
Could you try the new .NET 10 version?
Indeed looks like the same issue. Will verify in January when the update ships.
I am experiencing this same issue when attempting to update a WPF project to .NET 10. The System.Private.Windows.GdiPlus.dll isn't being referenced when building with WPF enabled and TargetFramework set to net10.0-windows.
I'm using this workaround until the fixed SDK is out:
<!-- Workaround for https://github.com/dotnet/wpf/issues/11246 -->
<Target Name="FixWpfReferences" AfterTargets="ResolveTargetingPackAssets" Condition="'$(UseWPF)' == 'true'">
<ItemGroup>
<SystemPrivateWindowsCoreRef Include="@(Reference)" Condition="'%(Filename)' == 'System.Private.Windows.Core'" />
<ReferencePath Include="@(SystemPrivateWindowsCoreRef->'%(RootDir)%(Directory)System.Private.Windows.GdiPlus.dll')">
<AssemblyName>System.Private.Windows.GdiPlus</AssemblyName>
</ReferencePath>
</ItemGroup>
</Target>
@jlaanstra could you explain how/where your fix would live? Looks like an extra .targets file or similar. I'm not familiar with that stuff, but I'd like to avoid adding the explicit reference for one out of 49 projects ... I would forget it. Having an extra file sounds like a smart idea.
@patrick-stalph How about add the code to Directory.Build.targets file? See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022
@patrick-stalph How about add the code to
Directory.Build.targetsfile? See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022
To use the workaround from @jlaanstra in a targets file, it is necessasry to add it inside a parent <Project>...</Project> element. For completeness; to workaround this issue create a Directory.Build.targets file in the solution directory containing:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!-- Workaround for https://github.com/dotnet/wpf/issues/11246 -->
<Target Name="FixWpfReferences" AfterTargets="ResolveTargetingPackAssets" Condition="'$(UseWPF)' == 'true'">
<ItemGroup>
<SystemPrivateWindowsCoreRef Include="@(Reference)" Condition="'%(Filename)' == 'System.Private.Windows.Core'" />
<ReferencePath Include="@(SystemPrivateWindowsCoreRef->'%(RootDir)%(Directory)System.Private.Windows.GdiPlus.dll')">
<AssemblyName>System.Private.Windows.GdiPlus</AssemblyName>
</ReferencePath>
</ItemGroup>
</Target>
</Project>
I also confirm the same error with .net 10.
@ericstj is this the same issue that we were tracking.
Yes, this is a duplicate of https://github.com/dotnet/sdk/issues/51173. We found too late to fix for GA but the fix will be part of 10.0.101 released shortly.