How do you load System.Drawing.dll and gdiplus.dll on Unity Mac?

I’ve got a project that is using an external assembly that requires System.Drawing.dll and gdiplus.dll.

Gdiplus.dll is a native dll for windows. There’s a version of it for mono platforms called libgdiplus. I’ve built this for the Mac, but can’t figure out how to convince Unity (Editor or Mac Standalone) to load this dylib (libgdiplus.dylib). The dylib is currently living in /opt/local/lib and that folder is on my system path.

When I attempt to run the project I get the following error:

DllNotFoundException: gdiplus.dll
System.Drawing.GDIPlus..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus
System.Drawing.Image.Dispose (Boolean disposing)
System.Drawing.Image.Finalize ()

The Mono documentation seems to indicate that Mono will automatically attempt to append lib to the name of the dll and swap the dll for dylib if it can’t find the requested dll. I’m not sure if the version of Mono that Unity uses does this as well?

Did anyone manage to get System.Drawing to work on OS X / iOS / Android?

I canont get the propsed solution to work.

I finally found a way to correct that error on Mac OSX High Sierra.

You have to add some links to your Unity configuration.

  1. First check your mono.framework
    version:

/Library/Frameworks/Mono.framework/Versions/5.4.1/lib/libgdiplus.dylib

  1. Then in your Unity config, you can
    find here:

"
/Applications/Unity/Unity.app/Contents/Mono/etc/mono/config
"

Add the following lines (change the version by yours):

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

Once you made this, save and restart Unity and let the magic play !

Hope it helps !

Hi!

For newer versions of Unity (Unity Hub) the mono config file to edit must be:


/Applications/Unity/Hub/Editor/X.X.X/Unity.app/Contents/MonoBleedingEdge/etc/mono/config


Wrong:

/Applications/Unity/Hub/Editor/X.X.X/Unity.app/Contents/Mono/etc/mono/config


Note: X.X.X is the version of Unity.

Greets.

I’ll chime in as another person hoping to find a solution to this.

I’ve been looking at the config file where dll remapping happens

(/Applications/Unity/Unity.app/Contents/Frameworks/Mono/etc/mono/config)

and copied into it the remapping lines that are in the MonoDevelop version of the file

(/Applications/Unity/MonoDevelop.app/Contents/Frameworks/Mono.framework/Versions/2.10.2/etc/mono):

dllmap dll=“gdiplus.dll” target=“/Applications/Unity/MonoDevelop.app/Contents/MacOS/…/Frameworks/Mono.framework/Versions/2.10.2/lib/libgdiplus.dylib” os=“!windows”

dllmap dll=“gdiplus” target=“/Applications/Unity/MonoDevelop.app/Contents/MacOS/…/Frameworks/Mono.framework/Versions/2.10.2/lib/libgdiplus.dylib” os=“!windows”

(those lines need delimiting if you copy them into the config file. I can’t get the delimited text to show up in the post. Just follow the convention you find in the file)

I added the os=“!windows” bit to both the MonoDevelop and Unity config files as that seems to be the standard incantation.

Then I restarted Unity and MonoConfig and pressed Play and got a slightly altered error message that shows that the new mapping is being seen:

DllNotFoundException: /Applications/Unity/MonoDevelop.app/Contents/MacOS/…/Frameworks/Mono.framework/Versions/2.10.2/lib/libgdiplus.dylib
System.Drawing.GDIPlus…cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus
System.Drawing.Image.Dispose (Boolean disposing)
System.Drawing.Image.Finalize ()

The dylib does live where the remapping points, so I can only imagine that the System.Drawing.GDIPlus constructor is for some reason not being found in the library?

A quick search of the dylib with ‘nm -g | grep -i gdiplus’ outputs just two symbols:

libgdiplus.0.dylib(single module):
0000d510 T _GdiplusShutdown
0000d650 T _GdiplusStartup

I’m no expert at reading the output, but I couldn’t find anything that looked like the constructor to me in a quick visual scan of the full output of ‘nm -g’.

I’m starting to feel like this may be all the yardage I can manage on this problem and I’m hoping someone out there can pick up the ball and manage a few more yards with it.

I have the same problem on the android platform, do you have a good solution ?

Hi,
i tried your solution it worked in the editor but didn’t work in the build

So, I am getting this error with OS X Catalina:

DllNotFoundException: /Users/bokken/build/output/Unity-Technologies/mono/external/buildscripts/add_to_build_results/monodistribution/lib/libgdiplus.dylib

  • I have tried all of the above solutions with no success. I have also tried adding the libgdiplus with homebrew.
  • Has anyone else had this problem and resolved it? Thanks!

I could solved it by

  1. Installing the GDI+ for mac brew install mono-libgdiplus

  2. Grabbing the /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/libgdiplus.0.dylib file and copying it to my project’s Assets/Plugins/libgdiplus.dylib

  3. Editing the/Applications/Unity/Hub/Editor/2020.3.2f1/Unity.app/Contents/MonoBleedingEdge/etc/mono/config file (note the version of the editor) by adding lines:

<dllmap dll="gdiplus" target="libgdiplus.dylib" />

<dllmap dll="gdiplus.dll" target="libgdiplus.dylib" />

This makes it work in the editor.

  1. After the build manually editing the xxx.app/Contents/MonoBleedingEdge/etc/mono/config file and adding the same lines.

This makes the build work.