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
3 changes: 1 addition & 2 deletions src/libraries/System.Drawing.Common/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
<UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides access to GDI+ graphics functionality.
safern marked this conversation as resolved.
Show resolved Hide resolved

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@
<data name="PlatformNotSupported_Drawing" xml:space="preserve">
<value>System.Drawing is not supported on this platform.</value>
</data>
<data name="PlatformNotSupported_Unix" xml:space="preserve">
<value>System.Drawing is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.</value>
safern marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="PrintDocumentDesc" xml:space="preserve">
<value>Defines an object that sends output to a printer.</value>
</data>
Expand Down Expand Up @@ -464,4 +467,4 @@
<data name="SystemDrawingCommon_PlatformNotSupported" xml:space="preserve">
<value>System.Drawing.Common is not supported on this platform.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
Link="Common\Interop\Windows\User32\Interop.LOGFONT.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Gdi32\Interop.RasterOp.cs"
Link="Common\Interop\Windows\Gdi32\Interop.RasterOp.cs" />
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs"
Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
Link="Common\System\Text\ValueStringBuilder.cs" />
<Compile Include="$(CommonPath)System\Obsoletions.cs"
Expand Down Expand Up @@ -207,7 +209,7 @@
<Compile Include="System\Drawing\Internal\GpPathData.cs" />
<Compile Include="System\Drawing\Internal\GPStream.cs" />
<Compile Include="System\Drawing\Internal\SystemColorTracker.cs" />
<Compile Include="System\Drawing\LocalAppContextSwitches.cs" />
<Compile Include="System\Drawing\LocalAppContextSwitches.Windows.cs" />
<Compile Include="System\Drawing\Pen.Windows.cs" />
<Compile Include="System\Drawing\Printing\DefaultPrintController.cs" />
<Compile Include="System\Drawing\Printing\ModeField.cs" />
Expand Down Expand Up @@ -243,8 +245,6 @@
<Compile Include="Interop\Windows\Interop.Shell32.cs" />
<Compile Include="Interop\Windows\Interop.User32.cs" />
<Compile Include="Interop\Windows\Interop.Winspool.cs" />
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs"
Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Gdi32\Interop.CombineRgn.cs"
Expand Down Expand Up @@ -359,6 +359,7 @@
<Compile Include="System\Drawing\GdiplusNative.Unix.cs" />
<Compile Include="System\Drawing\GdiPlusStreamHelper.Unix.cs" />
<Compile Include="System\Drawing\LibX11Functions.cs" />
<Compile Include="System\Drawing\LocalAppContextSwitches.Unix.cs" />
<Compile Include="System\Drawing\MarshallingHelpers.cs" />
<Compile Include="System\Drawing\Image.Unix.cs" />
<Compile Include="System\Drawing\Pen.Unix.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
safern marked this conversation as resolved.
Show resolved Hide resolved
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
Expand Down Expand Up @@ -62,6 +63,9 @@ internal static IntPtr LoadNativeLibrary()

private static void PlatformInitialize()
{
if (!LocalAppContextSwitches.EnableUnixSupport)
throw new PlatformNotSupportedException(SR.PlatformNotSupported_Unix);

LibraryResolver.EnsureRegistered();
safern marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

namespace System
{
internal static partial class LocalAppContextSwitches
{
private static int s_enableUnixSupport;
public static bool EnableUnixSupport
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return GetCachedSwitchValue(@"System.Drawing.EnableUnixSupport", ref s_enableUnixSupport);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"configProperties": {
"System.Drawing.EnableUnixSupport": true
safern marked this conversation as resolved.
Show resolved Hide resolved
}
}