8

I am trying to create a Bitmap with System.Drawing.Common in a .Net Core Console Application running on Ubuntu 18.04, but as soon as I execute the code it will show me:

The type initializer for 'Gdip' threw an exception.
   at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, HandleRef scan0, IntPtr& bitmap)
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
   at MidnightBot.Modules.AdminCommands.CreatePollAsync(String Term1, String Term2, String Description) in /home/MidnightBot/Modules/AdminCommands.cs:line 125
System.DllNotFoundException: Unable to load DLL 'libgdiplus': The specified module could not be found.
   at System.Runtime.InteropServices.FunctionWrapper`1.get_Delegate()
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
   at System.Drawing.SafeNativeMethods.Gdip..cctor()

Also I tried to do what was described here. But without success.

Thanks for any help.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Twenty
  • 5,234
  • 4
  • 32
  • 67
  • Did you only execute the command to install the dependencies? That is not enough, in fact you don't want to do that except as a developer developing the library. Just use the Ubuntu package manager to install the libgdiplus package. – NineBerry Sep 09 '18 at 17:42
  • It reads as if that dll wasn't present in the build artifacts. Does `dotnet restore` fix this by any chance? That should've stopped you at compile time, rather than runtime. – clarkitect Sep 09 '18 at 17:46
  • Yeah only did that, how would I install libdigplus ? just sudo apt-get install libdigplus @NineBerry – Twenty Sep 09 '18 at 17:49
  • `sudo apt-get install libgdiplus` – NineBerry Sep 09 '18 at 17:53
  • @NineBerry No more errors and the image is getting generated, but something wired going on going to update my question. – Twenty Sep 09 '18 at 18:10
  • @Twenty Write a new question if you have a different (new) problem. – NineBerry Sep 09 '18 at 18:13
  • Okay then I am going to create a new one thanks anyway! – Twenty Sep 09 '18 at 18:17

1 Answers1

6

You need to install the gdiplus library using a package manager. For example:

sudo apt-get install libgdiplus
NineBerry
  • 26,306
  • 3
  • 62
  • 93