-
Notifications
You must be signed in to change notification settings - Fork 211
[release/10.0.1xx] Expose System.Drawing.Common to WPF #2839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We prune System.Drawing.Common for all WindowsDesktop apps. Expose the reference so that we don't remove the package when someone might have needed it.
merriemcgaw
approved these changes
Oct 13, 2025
Member
merriemcgaw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
mmitche
approved these changes
Oct 13, 2025
Member
Author
|
/backport to main |
Contributor
|
Started backporting to main: https://github.com/dotnet/dotnet/actions/runs/18504189462 |
Member
|
Thank you. This can fix dotnet/wpf#11134 |
|
Is this fix available in .net 10 rc2 or it will be only available for the official release? |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes dotnet/sdk#51173
Customer Impact
We became aware of the issue through a customer report of a different issue.
When a customer is targeting .NET 10.0 and building a WPF application (not hybrid WPF+Winforms), references the package System.Drawing.Common, and uses types present in that package, they will see a compilation error:
There is a workaround -- add the following to the project;
The same bug can occur for an older .NET project if it explicitly opts into package pruning with
RestoreEnablePackagePruning. This workaround will work there as well.Background
The bug occurs because pruning represents all the runtime assemblies in the WindowsDesktop shared framework and will prune packages that overlap. WindowsDesktop has different reference vs runtime assemblies. It's references are factored into two sets: WPF and WindowsForms. There is one package in this set that is not shared between WindowsForms and WPF -- System.Drawing.Common. So when building for WPF the reference is pruned and a compilation error can occur.
We fix this by adding
System.Drawing.Commonto the default reference set for WPF. Moving forward we must follow the rule that any packages which overlap with shared frameworks must be represented in their entirety when that framework is referenced. We had similar bugs to this in ASP.NETCore, but there we chose to just remove the package from the pruning set since users would directly reference it and it did not have any past CVEs that would make more desirable to prune. System.Drawing.Common is more likely to be referenced transitively (it was in the customer report) - so we couldn't just drop it from the pruning list unless we also dropped every package which ever referenced it. It also has had past CVEs that make it desirable to prune to avoid false positive audit / CG alerts.Regression
Regressed in .NET 10.0 when enabling pruning for WindowsDesktop shared framework (earlier previews, repro'ed this in P5)
Testing
Verified customer repro is fixed. Adhoc testing of WPF templates. Tested https://github.com/Microsoft/WPF-Samples after retargeting to net10. Ran data analysis of namespace and type name collisions.
Risk
Medium
We are adding new types to the default reference set, and some of those types conflict with WPF types if using statements for both are present. This should only ever break compile-time (not runtime), only for folks targeting net10.0, and the break is normal/expected for what folks see on retargeting. They will know what to do to resolve the break without reading any documentation.
We are effectively trading a break that is hard to diagnose, with a non-intuitive workaround for a break that is easy to diagnose with an intuitive fix.
We tried to measure the likelihood of both breaks. The internal component governance data shows about 54 hits of projects that reference drawing and target Windows desktop - rather small in the grand scheme of things (our popular packages in this feed are ~10-20k). Most likely internal data has fewer WPF client applications. We don't have great data, but I looked to a github search was surprised to search for cases of a drawing reference in a WPF app. I expected those to be few, but my search found 5K source hits across github (looking for code-behind files with a using statement for drawing) and I was able to reproduce the bug in more than one of those projects in the first page of results.
I did a similar search for cases where our newly introduced type collisions might cause a compiler error. I couldn't find any. The data set was similar - WPF sources using Drawing - but most of those had already dealt with the type conflicts present in the base-shared framework's System.Drawing.Primitives assembly. Any case of .NETFramework source (or source ported from .NETFramework) had also already dealt with the conflicts since all the System.Drawing types were in a single System.Drawing assembly in netfx.