According to https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only System.Drawing.Common is no longer supported under on non-windows OS UNLESS a runtime configuration switch is set. I've setup runtimeconfig.template.json and see the switch:
"runtimeOptions": {
"configProperties": {
"System.Drawing.EnableUnixSupport": true
}
}
inside the file .runtimeconfig.json in bin/Debug/net6.0
However when I run the app in a linux box using dotnet exec app.dll
I still get PlatformNotSupportedException
The following worked for me.
Adding the following line to the .csproj file in a
PropertyGroup
section:Next create a file named runtimeconfig.template.json in the same directory as your project file containing:
I used the
dotnet publish
command, which created a [YourAppNameHere].runtimeconfig.json file in the output directory I supplied to thedotnet publish
command.For my asp.net project, the publish resulted in the following [YourAppNameHere].runtimeconfig.jsonfile:
This worked, where trying to follow the documentation on the page linked to in the question did not. I think this is because I was adding the
runtimeOptions
section in the runtimeconfig.template.json file, but thedotnet publish
command was also adding a section namedruntimeOptions
, which seems to have prevented the runtime from seeing theSystem.Drawing.EnableUnixSupport
option.For this reason, I excluded the
runTimeOptions
section in my runtimeconfig.template.json file as the publish resulted in the following file that did not work:Note the nested
runtimeOptions
, which I believe was causing it to fail when trying to follow the documentation in the link from the question.