- Home /
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?
I'd love to know if you ever solved this because I'm also having the same issue trying to integrate the AForge imaging library with Unity.
No, I never did manage to solve this. Sorry. I believe it was AForge that I was working with too.
Now in 2017, do we have a solution for this?
I'm simply trying to make use of the System.Drawing.Bitmap class, on Android, but the construction is failing due to "gdiplus.dll" not being found.
Thanks in advance...
Answer by DVFrance · Mar 01, 2018 at 06:33 PM
I finally found a way to correct that error on Mac OSX High Sierra.
You have to add some links to your Unity configuration.
First check your mono.framework version:
/Library/Frameworks/Mono.framework/Versions/5.4.1/lib/libgdiplus.dylib
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 !
Hey, I did exactly what you told, but I am getting same error but now with the path I specified. /Applications/Unity/$$anonymous$$onoDevelop.app/Contents/Frameworks/$$anonymous$$ono.framework/Versions/Current/lib/libgdiplus.dylib
I checked , the gdiPlus is there only.
Hi, Take a look on your path, version number is missing, so I think the path does not exist :
/Applications/Unity/$$anonymous$$onoDevelop.app/Contents/Frameworks/$$anonymous$$ono.framework/Versions/versionNumber/lib/libgdiplus.dylib
Let me know.
I had the same problem and it is exactly what I needed. It works perfectly. Thanks for the solution.
Answer by emisael-carrera · Jun 25, 2019 at 02:52 AM
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.
Answer by martinj · Aug 13, 2014 at 03:19 PM
Did anyone manage to get System.Drawing to work on OS X / iOS / Android?
I canont get the propsed solution to work.
Unfortunately no. There is some hope down the road with SparseTextures, but $$anonymous$$avericks doesn't support the required gl call (ARB_sparse_texture) and as far as I've been able to tell, Yosemite won't either. $$anonymous$$aybe next year for $$anonymous$$ac. I don't know what gl versions are supported on Android; that's not a platform I've been supporting yet.
Answer by Brian Deans-Rowe · Jun 20, 2013 at 06:37 PM
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.
Answer by RedLing · May 08, 2018 at 02:31 AM
I have the same problem on the android platform, do you have a good solution ?