Skip to content
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

Make System.Drawing.Common throw on Unix unless a config switch is set #55962

Merged
merged 9 commits into from
Jul 21, 2021

Conversation

safern
Copy link
Member

@safern safern commented Jul 19, 2021

I choose the GDIP startup process to throw the PNSE as that is executed via an static constructor and from the scan I did there is not any interesting types left in System.Drawing.Common that don't use GDI+. Most of the ones that don't use it are data holders to represent data gathered from GDI+, or to pass in to another class as a parameter and then go down to the native layer.

But doing it from the GDIP startup process it means that some of these types that don't use or reference GDI+ directly can be used/created (they are not interesting to use), but those would not throw PNSE. Are we OK with that and then in .NET 7+ make every type on the assembly just throw or do we want to follow a different approach?

Relates to: dotnet/designs#234

@ghost
Copy link

ghost commented Jul 19, 2021

Tagging subscribers to this area: @safern, @tarekgh
See info in area-owners.md if you want to be subscribed.

Issue Details

I choose the GDIP startup process to throw the PNSE as that is executed via an static constructor and from the scan I did there is not any interesting types left in System.Drawing.Common that don't use GDI+. Most of the ones that don't use it are data holders to represent data gathered from GDI+, or to pass in to another class as a parameter and then go down to the native layer.

But doing it from the GDIP startup process it means that some of these types that don't use or reference GDI+ directly can be used/created (they are not interesting to use), but those would not throw PNSE. Are we OK with that and then in .NET 7+ make every type on the assembly just throw or do we want to follow a different approach?

Relates to: dotnet/designs#234

Author: safern
Assignees: -
Labels:

area-System.Drawing

Milestone: -

Co-authored-by: Immo Landwerth <immo@landwerth.net>
@jkotas
Copy link
Member

jkotas commented Jul 19, 2021

in .NET 7+ make every type on the assembly just throw

Yes, I think so - same as what we do for other OS-specific libraries.

@jkotas
Copy link
Member

jkotas commented Jul 19, 2021

I think this should be marked as breaking change and have breaking change template filled.

@safern safern added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Jul 19, 2021
@ghost ghost added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jul 19, 2021
@ghost
Copy link

ghost commented Jul 19, 2021

Tagging @dotnet/compat for awareness of the breaking change.

@safern
Copy link
Member Author

safern commented Jul 20, 2021

@ericstj
Copy link
Member

ericstj commented Jul 20, 2021

Do we care about that support? Or should I just disable those tests cases on non-windows?

Those tests are using Drawing. We can have them set the flag as well https://github.com/dotnet/runtime/pull/55962/files#diff-8409367c188e7be18ecf8735b3d8016c9ca5f9c2ec610eb2ec122bef2a4d94feR3. If we want we can also add a test to validate the failing scenario as you did here.

@safern
Copy link
Member Author

safern commented Jul 20, 2021

Thanks. I didn't know if that scenario was important for Resources on Unix. I'll update the tests accordingly.

@safern
Copy link
Member Author

safern commented Jul 21, 2021

I've created the breaking change issue: dotnet/docs#25257

{
RemoteExecutor.Invoke(() =>
{
AppContext.SetSwitch("System.Drawing.EnableUnixSupport", false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set it if it's false by default? Seems we should test default, and also test when explicitly enabled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We set it to false here as the runtimeconfig is setting it to true and the remote executor uses that same runtimeconfig file when creating the new process.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we accidentally changed the default to true, would any test fail?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I could however try to add a test to ensure the default is false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to achieve this we would need to either create our own process or a separate assembly that doesn't set the value on the runtimeconfig.json, so I believe it is pretty complicated and not worth it, as in order to change the default value we would have to hardcode it in LocalAppContextSwitches like here:

if (switchName == "Switch.System.Runtime.Serialization.SerializationGuard")

Given that this is a one time release thing and already late on the release I think we are safe to not test that default value.

@karelz
Copy link
Member

karelz commented Jul 21, 2021

Http3_MsQuic test failures are tracked in #56090. Should be fixed and merged shortly. Sorry for the inconvenience!

@safern
Copy link
Member Author

safern commented Jul 21, 2021

Test failures are unrelated. Merging.

@safern safern merged commit 2ccf787 into dotnet:main Jul 21, 2021
@safern safern deleted the DrawingWindowsOnly branch July 21, 2021 22:59
@safern
Copy link
Member Author

safern commented Jul 21, 2021

/backport to release/6.0-preview7

@github-actions
Copy link
Contributor

Started backporting to release/6.0-preview7: https://github.com/dotnet/runtime/actions/runs/1054284714

@ghost ghost locked as resolved and limited conversation to collaborators Aug 20, 2021
@ericstj ericstj added this to the 6.0.0 milestone Sep 30, 2021
@safern
Copy link
Member Author

safern commented Sep 30, 2021

@ericstj ericstj removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Sep 30, 2021
@ericstj
Copy link
Member

ericstj commented Sep 30, 2021

Thanks, removed the label to indicate that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Drawing breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants