Working with libgdiplus.dylib error on Mac and Unity

Reghill J Manuelraj
XRPractices
Published in
2 min readAug 1, 2019

--

I am working on a project that makes use of System.Drawing.dll and gdiplus.dll. I am currently working on macOS High Sierra and got stuck with the following error.

DllNotFoundException:/Users/builduser/builds/vm/mono/external/buildscripts/add_to_build_results/monodistribution/lib/libgdiplus.dylib System.Drawing.GDIPlus..cctor ()(at < 7026bacc22c446e78b11ff1 30428 baf7 > : 0 ) Rethrow as TypeInitializationException: The type initializer for ‘System.Drawing.GDIPlus’ threw an exception. System. Drawing. Bitmap.. ctor (System.Int32 width, System.Int32 height, System. Drawing. Imaging. PixelFormat format) (at <7026bacc22c446e78b11ff130428baf7>:0)(wrapper remoting-invoke-with-check)System. Drawing. Bitmap.. ctor (int, int, System. Drawing. Imaging. PixelFormat)

In wiki terms, dll stands for dynamic link library. Why is it used? It is used for better performance basically. The .dll files are imported to the target project you are working on, and do not get compiled with other code. They are dynamically linked with the program only when needed. It saves a lot of RAM usage and boosts performance.

System.drawing.dll is a Windows dll file and it will be a problem while working with a Unity project. So how to arrive at the solution?

First , we should check the version of Mono.framework. Open terminal , navigate through /Library/Frameworks/Mono.framework/Versions/ and check for the available versions by listing the files present in Versions.

Secondly, in Terminal, open /Applications/ Unity/ Hub/ Editor/ X.X.X/ Unity.app/Contents/MonoBleedingEdge/etc/mono/config. Note that X.X.X is the version of Unity that you are using for your project.

In the case of mine, my project makes use of Unity version 2018.4.4f1 and all the newer versions of Unity works fine with the above-mentioned step. In the case of older versions, the second step would be looking slightly different.

In terminal open /Applications/ Unity/ Unity.app/ Contents/ Mono/ etc/ mono/ config.

Your config file would look something like this.

In the config file, add the following line of code for the error to vanish away from your way.!

<dllmap dll="gdiplus" target="/Library/Frameworks/Mono.framework/Versions/X.X.X/lib/libgdiplus.dylib" />

<dllmap dll="gdiplus.dll" target="/Library/Frameworks/Mono.framework/Versions/X.X.X/lib/libgdiplus.dylib" />

Here X.X.X is the Mono.framework Version that you make use of in the project. This version is determined by the first step mentioned above.

Now after adding these lines of code in the config file, your Unity will no longer remember the previous dll error and will provide you the happiness of getting intended output (if no other error exists 😉).

--

--

Reghill J Manuelraj
XRPractices

An heuristic Application Developer with a hobby of scribbling my experiences