3

I want to use system.drawing in my project but I cant make it work. I have found this question, but it shows only how to add SQLite.NET-PCL, if I try doing it the same way for System.Drawing it doesnt work.

Here is my project.json:

{
"version": "1.0.0-*",
"buildOptions": {
  "debugType": "portable",
  "emitEntryPoint": true
},
"dependencies": {
},
"frameworks": {
  "net461": {
    "dependencies": {
      "OpenTK": "2.0.0*"
    }
  }
},
"runtimes": {
  "win7-x64": {},
  "win10-x64": {}
}
}

If I try adding System.Drawing it tries to autocomplete to "System.Drawing" : "1.0.0-beta004" which doesnt work with opentk. I am trying to save a image from OpenTK. Is there a way to make this work in VS code?

Community
  • 1
  • 1
Tygrak
  • 31
  • 1
  • 4
  • 1
    "Doesn't work" — best error description ever. – Uwe Keim Feb 25 '17 at 12:18
  • 1
    System.Drawing can only work on the desktop version of .NET. So can't be used in the .NETCore projects that VSCode supports, you'd need the VS community edition. There might be an alternative, but when you don't explain what you are trying to accomplish then it would be just wild guessing. – Hans Passant Feb 25 '17 at 12:37
  • @Uwe Keim `The type 'Size' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [net461]` This is what happens when I try using it with the 1.0.0-beta. – Tygrak Feb 25 '17 at 12:37
  • @HansPassant Thank you! I didnt know that. Still I dont understand when I am using the net461 framework why doesnt it work? I am trying to save a image from OpenTK. Should I switch to VS community edition then? – Tygrak Feb 25 '17 at 12:41

2 Answers2

9

This problem cost me a good hour of my time trying to solve. Here's the solution that worked for me:

dotnet add package System.Drawing.Common

It appears that System.Drawing is not compatible with .NET Core but Microsoft has released the cross-platform System.Drawing.Common package to compensate that.

Full article/credits/source to here: https://www.hanselman.com/blog/HowDoYouUseSystemDrawingInNETCore.aspx

Marius B
  • 769
  • 3
  • 16
  • 35
ownagesbot
  • 91
  • 1
  • 5
0

I have found the library "CoreCompat.System.Drawing" : "1.0.0-beta006", which kind of works with OpenTK.

Tygrak
  • 31
  • 1
  • 4