Skip to content

.NET10 WPF: C# 8.0 'using' declarations behave differently than its try/final equivalent (assembly reference issue) #51931

@SerjPo

Description

@SerjPo

Describe the bug

For .NET10 WPF app it is not possible to use C# 8.0 'using' declarations any more to reference Graphics class from System.Drawing namespace.
The type 'IGraphics' 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'.

To Reproduce

Here's the csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net10.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

</Project>

And here's App.xaml.cs:

using System.Drawing;
using System.Windows;

namespace WpfApp1
{
    public partial class App : Application
    {
        private void Test()
        {
            using var g = Graphics.FromImage(null); // <- The type 'IGraphics' 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'.

            // expanded using declarations: no compile errors
            Graphics? g2 = null;
            try
            {
                g2 = Graphics.FromImage(null);
            }
            finally
            {
                g2?.Dispose();
            }
        }
    }
}

Both VS 2026 Intellisense and the compiler show two errors:

Error (active)	CS0012	The type 'IGraphics' 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'.	WpfApp1	D:\Projects\1\WpfApp1\App.xaml.cs	10	
Error (active)	CS0012	The type 'IGraphicsContextInfo' 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'.	WpfApp1	D:\Projects\1\WpfApp1\App.xaml.cs	10	

Interestingly, if we expand the 'using' declaration into try/finally block (see the code above), such errors will not occur.

We can't add 'System.Private.Windows.GdiPlus' assembly because as its name suggest it is private and can't be found in nuget repo.
We can add 'System.Drawing.Common' v10.0.0 nuget package, but it does not help.

Here is info about other project types / .NET versions:
For .NET10 console app project the issue is not reproduced (we need to add 'System.Drawing.Common' v10.0.0 nuget package).
For .NET9 WPF project the issue is not reproduced (we need to add 'System.Drawing.Common' v9.0.11 nuget package).

Exceptions (if any)

Further technical details

details of dotnet --info

.NET SDK: Version: 10.0.100 Commit: b0f34d51fc Workload version: 10.0.100-manifests.5fb86115 MSBuild version: 18.0.2+b0f34d51f

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.0
Architecture: x64
Commit: b0f34d51fc

.NET SDKs installed:
10.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
DOTNET_CLI_UI_LANGUAGE [en-US]
DOTNET_GCHeapCount [2]
DOTNET_GCNoAffinitize [1]
DOTNET_MULTILEVEL_LOOKUP [0]
DOTNET_TC_CallCountThreshold [1000]
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit [0]
DOTNET_gcConcurrent [0]
Detected COMPlus_* environment variable(s). Consider transitioning to DOTNET_* equivalent.

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

- VS 2026 Version: 18.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedRequest triage from a team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions