Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core and System.Drawing

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

like image 234
pantonis Avatar asked Nov 30 '16 15:11

pantonis


People also ask

What is System drawing in C#?

The Graphics class provides methods for drawing to the display device. Classes such as Rectangle and Point encapsulate GDI+ primitives. The Pen class is used to draw lines and curves, while classes derived from the abstract class Brush are used to fill the interiors of shapes.

Is System drawing common cross-platform?

Drawing. Common is used cross-platform mostly for image manipulation, such as QR code generators and text rendering. We haven't noticed heavy graphics usage, as our cross-platform graphics support is incomplete. The usages we see of System.

Is .NET Core WinForms cross-platform?

NET Core Runtime is cross-platform and can run on Mac and Linux, when using desktop frameworks with . NET Core, your app still relies on the underlying Windows platform. WinForms uses the WindowsAPI and Hwnd style-rendering and WPF uses DirectX; both of those platforms are directly tied to the native Windows OS.

Can you mix .NET Core and .NET framework?

Net Framework assembly into a Core or Standard project, it will compile but with the dreaded “This package may not be fully compatible with your project” warning. You can only verify the availability of all the types by running the project, so you can only guarantee compatibility through run-time testing.


2 Answers

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/

like image 189
infl3x Avatar answered Sep 21 '22 16:09

infl3x


Add NuGet reference Microsoft.Windows.Compatibility

Notice: mark "Include prerelease"

Of course, it works only if prerelease packages are OK for you.

like image 27
Nikolay Pakudin Avatar answered Sep 21 '22 16:09

Nikolay Pakudin