Why Do I get PlatformNotSupportedException for System.Drawing.Common when running in a windows environment

Viewed 23

I am developing an ASP.NET application in .NET 6. I reference ClosedXML package, which internally uses System.Drawing.Common. I understand from this explanation in Microsoft's docs that this is not supported on Linux. Developing on a windows machine this works fine. However, when I publish to a windows IIS server with this command:

dotnet publish ".\path\project.csproj" -o ".\path\bin\app.publish --runtime win-x64 --no-self-contained --configuration Release --force /p:EnvironmentName=Test
xcopy .\path\bin\app.publish \\server\c$\remote\iis\path /ydisce 

...then browse to the app, calls using ClosedXML that rely on System.Drawing.Common (specifically AdjustToContents) fail with a PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.

If I publish without specifying --runtime, then it works, but also includes a bunch of runtime folders I don't think it should need (ie \runtimes\unix*, win-x86, etc.). I'd like to publish just the files I need in the given environment, but also am just curious because I don't understand why I'm getting PlatformNotSupportedException in this case. It seems like System.Drawing.Common should just be checking the OS and seeing it's on windows.

0 Answers
Related