.NET Core and System.Drawing
Solution 1
System.Drawing
is not a good option with ASP.NET
If you want graphics manipulation i suggest to use ImageSharp (https://github.com/JimBobSquarePants/ImageSharp) on .Net Core or ImageProcessor (http://imageprocessor.org/) / ImageResizer (https://imageresizing.net/) on .Net Framework
Also, if you really need to use System.Drawing
change frameworks in your project.json to netstandard1.6
and add in dependencies "NETStandard.Library": "1.6.1"
Solution 2
I know this is old, but there is now a port of the library called System.Drawing.Common
. Try installing that one with NuGet.
To make this possible, there is a metapackage called Windows Compatibility Pack
. However, this metapackage includes many, many Windows related APIs (distributed as packages).
Source: https://developers.de/2018/01/22/how-to-use-system-drawing-in-net-core/
Solution 3
Add NuGet reference Microsoft.Windows.Compatibility
Notice: mark "Include prerelease"
Of course, it works only if prerelease packages are OK for you.
Solution 4
When you want to use asp.net core on .NET Full Framework only you can reference the old class libraries like this
{
"version": "1.0.0-*",
"frameworks": {
"net452": {
"dependencies": {
},
"frameworkAssemblies": {
"System.Drawing": "4.0.0.0",
}
}
}
}
Related videos on Youtube
pantonis
Updated on July 09, 2022Comments
-
pantonis almost 2 years
I am trying to reference System.Drawing in a .net core console app targeting net46 but the assembly is not there. According to MS if you use dotnetcore System.Drawing is not available. But if you reference full .net framework you should be able to use it
This is my project.json
{ "version": "1.0.0-*", "buildOptions": { "emitEntryPoint": true }, "dependencies": { }, "frameworks": { "net46": { } } }
Any idea what is the problem
-
Tseng over 7 yearsDid you read your own question in the first place? Your first sentence says I am trying to reference System.Drawing in a .net core console app targeting net46, which tells me you don't understand difference between ASP.NET Core and .NET Core. I just explained it for you, to help you avoid confusion in future or to fix your question. Because for people reading the question its not clear if you want to run it on .NET Core, .NET framework. It's contradicting, because .NET Core and .NET Framework are mutually exclusive. ASP.NET Core runs on both, but ASP.NET Core is a webstack, not runtime
-
pantonis over 7 years@Tseng who mentioned asp.net? You mentioned it man.
-
pantonis over 7 yearsI totally agree with you. I meant the VS template. But I did not mention ASP.NET
-
-
pantonis over 7 yearsThanks. Although it is still in Alpha version and cannot find any documentation. Hope that no bugs exist because I will run it in production env. very soon.
-
Jérôme MEVEL over 7 yearsI just realized I also target full .NET Framework in my project and I have a reference to
"NETStandard.Library": "1.6.1"
, but how come? .NET Standard is a kind of "contract" exposing some APIs that all Frameworks should implement.System.Drawing
is quite empty in .NET Core for the moment and I've been told on Twitter that even with .NET Standard 2.0 coming soon there will be no System.Drawing implementation similar to what is existing on full .NET Framework. I don't understand -
Christian Gollhardt almost 6 yearsAlso important to consider: As the name suggest: It's only working on windows. This might or might not be a problem.
-
Frederik Carlier over 5 yearsSystem.Drawing.Common works on Windows, Linux and macOS. On Linux and macOS, you need to install its native dependency, ligdiplus. You can do
apt-get install -y libgdiplus
orbrew install mono-libgdiplus
. -
Simon Mourier over 4 yearsNow that netcore3 is out, this should be the accepted answer.
-
Douglas Gaskell almost 4 yearsUnfortunately the image format of imagesharp is very limited, with no webp support at all. Pmuch all libraries that do support webp and others rely on system.drawing.
-
Luke about 2 yearsI removed the link because the domain has been dropped and now links to spam.
-
Sana Ahmed almost 2 yearsIt will no longer be supported on other platforms in net core 7 just FYI