wpf icon indicating copy to clipboard operation
wpf copied to clipboard

[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'.

Open jlaanstra opened this issue 1 month ago • 5 comments

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

jlaanstra avatar Nov 11 '25 22:11 jlaanstra

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

lindexi avatar Nov 12 '25 00:11 lindexi

@jlaanstra I think this issues fixed in https://github.com/dotnet/dotnet/pull/3120

Could you try the new .NET 10 version?

lindexi avatar Nov 12 '25 00:11 lindexi

Indeed looks like the same issue. Will verify in January when the update ships.

jlaanstra avatar Nov 12 '25 01:11 jlaanstra

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.

skills697 avatar Nov 13 '25 15:11 skills697

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 avatar Nov 13 '25 18:11 jlaanstra

@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 avatar Nov 18 '25 16:11 patrick-stalph

@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

lindexi avatar Nov 19 '25 00:11 lindexi

@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

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>

CodeChief avatar Nov 19 '25 18:11 CodeChief

I also confirm the same error with .net 10.

bernox89 avatar Nov 23 '25 17:11 bernox89

@ericstj is this the same issue that we were tracking.

harshit7962 avatar Nov 24 '25 05:11 harshit7962

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.

ericstj avatar Nov 24 '25 18:11 ericstj