A few days ago there was an issue raised in my QrCoder project. It was reported that the code would not run under Linux, as the following error message would occur:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.Drawing.KnownColors' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'gdiplus.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at System.Drawing.GDIPlus.GdiplusStartup(UInt64& token, GdiplusStartupInput& input, [...]
However the error message had its origin not in my QrCoder, but in the interplay of the .NET core framework with the GDI Plus library. The .NET Core Framework tries to access “gdiplus.dll” when accessing “System.Drawing.GDIPlus”, which is simply not available on Linux.
First solution approach
First, ensure that GDI+ is installed at all. This can be done with the following shell command:
sudo apt-get install libgdiplus
If libgdiplus is installed, however, another important step is missing …
Link libgdiplus for .NET Core
Because the .NET Core Framework, regardless of the operating system, is looking for the library with the suffix “.dll”, it does not find the lib on Linux, although a valid version of the libgdiplus is installed. To fix this issue we create a symbolic link to the libgdiplus.so file.
cd /usr/lib sudo ln -s libgdiplus.so gdiplus.dll
After this, the error message should disappear. Now you will be able to use the QrCoder including the .NET Core Framework under Linux.