Bug 3263 - Create Installer (mmp) System.DllNotFoundException: gdiplus.dll
Summary: Create Installer (mmp) System.DllNotFoundException: gdiplus.dll
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Mac Add-in ()
Version: 2.8.6
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Miguel de Icaza [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2012-02-08 06:21 UTC by AndyW
Modified: 2013-01-10 16:45 UTC (History)
12 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (23.56 KB, application/x-zip-compressed)
2012-02-08 06:21 UTC, AndyW
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description AndyW 2012-02-08 06:21:28 UTC
Created attachment 1324 [details]
Test Project

Create a new MonoMac project - which naturally references System.Drawing.

Use any class from the System.Drawing namespace, e.g Bitmap - all works fine on Dev Machine. (Sample project attached)

Create Mac Installer - [x] Include Mono in application bunddle - Don't link assemblies, [x]Create installer package.

Now install this pkg on a machine without Mono. 

Start the application, it appears on the dock for a second, but then closes. Looking at the Console the following exception message is displayed:

08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: gdiplus.dll
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest:   at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest:   at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0 
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest:   --- End of inner exception stack trace ---
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at System.Drawing.Bitmap..ctor (int,int,System.Drawing.Imaging.PixelFormat) <0x00033>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at System.Drawing.Bitmap..ctor (int,int) <0x0001b>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap..ctor (int,int) <0x00037>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at DrawingTest.MainWindowController.Initialize () <0x00027>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at DrawingTest.MainWindowController..ctor () <0x00027>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at DrawingTest.AppDelegate.FinishedLaunching (MonoMac.Foundation.NSObject) <0x00023>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at (wrapper dynamic-method) object.[DrawingTest.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <0x00033>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at (wrapper native-to-managed) object.[DrawingTest.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <0x000fb>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0x00003>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at MonoMac.AppKit.NSApplication.Main (string[]) <0x00017>
08/02/2012 10:23:32.076 [0x0-0xc50c5].com.yourcompany.DrawingTest: at DrawingTest.MainClass.Main (string[]) <0x00017>

After inspecting the application bundle, the config file is missing the <dllmap for gdiplus, and the dylib is missing in resources.

After reading this thread: http://mono.1490590.n4.nabble.com/MonoMacPackager-System-DllNotFoundException-gdiplus-dll-td3244915.html Miguel says this is a limitation of the packager and should be fixed shortly.

According to this bug old report https://bugzilla.novell.com/show_bug.cgi?id=663506 the issue was resolved in February and MonoMac 1.0 was released on March 17th, 2011 - I would assume this fix made it into version 1, but there's always a possibility it didn't.

As far as I'm aware everything is up to date (see below), if this is a new/old bug does a work around exist? Cheers

MonoDevelop 2.8.6.4
Runtime:
	Mono 2.10.9 (tarball Fri Feb  3 18:03:38 EST 2012)
	GTK 2.24.9
	GTK# (2.12.0.0)
Apple Developer Tools:
	 Xcode 4.2.1 (834)
	 Build 4D502
Monotouch: 5.2.3
Mono for Android not installed
Build information:
	Release ID: 20806004
	Git revision: ca00645c0f884e6cab8e8794fc7d65b2f6f3e5c3
	Build date: 2012-01-27 21:13:18+0000
Operating System:
	Mac OS X 10.7.3
Comment 1 Miguel de Icaza [MSFT] 2012-02-08 12:28:18 UTC
The bug was incorrectly closed.

The actual code to copy libgdiplus.dylib to the target package was never implemented.

As a workaround, you could try copying libgdiplus.dylib manually into to your package and try it out.
Comment 2 shill 2012-06-20 19:39:18 UTC
This is a problem with v3.0.3.2 as well!

The libgdiplus.dylib has dependencies as well so you need to copy much more than just that one library.

MonoDevelop 3.0.3.2
Installation UUID: 1cbc3b4f-5129-4caa-b5b5-4fd07472620c
Runtime:
	Mono 2.10.9 (tarball)
	GTK 2.24.10
	GTK# (2.12.0.0)
	Package version: 210090011
Apple Developer Tools:
	 Xcode 4.2 (828)
	 Build 4C199
Monotouch: 5.2.12
Mono for Android not installed
Build information:
	Release ID: 30003002
	Git revision: 7bf6ac0ca43c1b12703176ad9933c3484c05c84c-dirty
	Build date: 2012-06-16 04:36:10+0000
	Xamarin addins: 62ad7268d38c2ece7e00dc32960bd3bdab8fec38
Operating System:
	Mac OS X 10.6.8
	Darwin shill-iMac.local 10.8.0 Darwin Kernel Version 10.8.0
	    Tue Jun  7 16:33:36 PDT 2011
	    root:xnu-1504.15.3~1/RELEASE_I386 i386
Comment 3 tlapse 2012-08-02 13:51:38 UTC
It is still in 3.0.3.5. This is a critical bug preventing me from shipping a product.

If there is a work around, please explain the details. Exactly where do I copy libgdiplus.dylib? What other libs need to be copied?

Thank you!
Comment 4 shill 2012-08-02 14:07:48 UTC
This is a horible workaround but this is what I had to do to get our app working.

Keep in mind your app may use different system libraries.


snippet from my Ant build.xml that gets run after the compilation is complete:

<!-- Copy the required libraries to the APP bundle -->
<copy todir=".../your.app/Contents/MonoBundle" overwrite="true">
  <fileset dir=".../YouProject/bin/Release">
    <include name="*.exe"/>
    <include name="*.dll"/>
    <include name="*.config"/>
  </fileset>
</copy>
<!-- Copy the required gdiplus libraries to the APP bundle -->
<copy todir=".../your.app/Contents/MonoBundle" overwrite="true">
  <fileset dir="/Library/Frameworks/Mono.framework/Libraries">
    <include name="libgdiplus*.dylib"/>
    <include name="libglib*.dylib"/>
    <include name="libcairo*.dylib"/>
    <include name="libfreetype*.dylib"/>
    <include name="libjpeg*.dylib"/>
    <include name="libtiff*.dylib"/>
    <include name="libgif*.dylib"/>
    <include name="libpng*.dylib"/>
    <include name="libfontconfig*.dylib"/>
    <include name="libintl*.dylib"/>
    <include name="libpixman*.dylib"/>
    <include name="libexpat*.dylib"/>
  </fileset>
</copy>
<!-- Copy the required System libraries to the APP bundle -->
<copy todir=".../your.app/Contents/MonoBundle" flatten="true" overwrite="true">
  <fileset dir="/Library/Frameworks/Mono.framework/Libraries/mono/gac">
    <include name="**/4.0*/Microsoft.CSharp.dll"/>
    <include name="**/4.0*/System.dll"/>
    <include name="**/4.0*/System.Configuration.dll"/>
    <include name="**/4.0*/System.Core.dll"/>
    <include name="**/4.0*/System.Data.dll"/>
    <include name="**/4.0*/System.Data.DataSetExtensions.dll"/>
    <include name="**/4.0*/System.Data.Linq.dll"/>
    <include name="**/4.0*/System.Drawing.dll"/>
    <include name="**/4.0*/System.EnterpriseServices.dll"/>
    <include name="**/4.0*/System.Runtime.Serialization.dll"/>
    <include name="**/4.0*/System.Security.dll"/>
    <include name="**/4.0*/System.ServiceModel.dll"/>
    <include name="**/4.0*/System.Web.dll"/>
    <include name="**/4.0*/System.Windows.Forms.dll"/>
    <include name="**/4.0*/System.Xaml.dll"/>
    <include name="**/4.0*/System.Xml.dll"/>
    <include name="**/4.0*/WindowsBase.dll"/>
  </fileset>
</copy>
<copy todir=".../your.app/Contents/MonoBundle" flatten="true" overwrite="true">
  <fileset dir="/Library/Frameworks/Mono.framework/Libraries/mono/4.0">
    <include name="mscorlib.*"/>
  </fileset>
</copy>
Comment 5 tlapse 2012-08-02 15:55:18 UTC
Thanks for the work around. 
I appreciate your help.

I tried it, but it's still not working for me.
Comment 6 Jonathan Brodsky 2012-08-18 19:28:25 UTC
Thanks for this. I was able to get it working with some modifications. I needed to remove the .dylibs that were produced from the symlinks, and just leave in the ones that the symlinks were pointing to, i.e. leave in libgif.4.dylib, and take out libgif.dylib
Comment 7 Kristian Dupont 2012-08-27 07:47:02 UTC
Jonathan,

so you copy the .dylib files into your .app and then remove the symlinks?

I copied libgdiplus.dylib into the Resources folder which helped but it then complains about not finding libglib-2.0.0.dylib and it seems to insist on searching in /Library/Frameworks/Mono.framework/Versions/2.10.9/lib.

I am not sure where to go from here..
Comment 8 Joachim Graesser 2012-09-10 05:11:52 UTC
Same problem here.
To try out the workarounds provided here, I created a simple MessageBox application using System.Windows.Forms with the MonoMac (Empty project) project template on MonoDevelop 3.0.3.5 (Mono version 2.10.9). Application runs fine as long as "Include the Mono runtime in the application bundle" is turned of. As soon as it's enabled the Application will crash with the libgdiplus (or some of it's dependencies) not found issue.
Any further hint/solution to get such a simple application running standalone?

Joachim
Comment 9 Kristian Dupont 2012-09-10 15:03:00 UTC
Joachim,

as suggested in this question on StackOverflow: http://stackoverflow.com/questions/12246933/mono-mac-packager-doesnt-work-with-gdiplus-dll, I decided to go with CoreGraphics instead.
Comment 10 Joachim Graesser 2012-09-13 04:33:35 UTC
Thanks for the suggestion Kristian,

unfortunately this is not an option for us, since we have a really big project (based on win32 .net) that we have already converted/adapted to mono and works fine when started within MonoDevelop. All we would need now for shipping is a working version of the packager for System.Windows.Forms (and it's dependencies).

Nevertheless I have managed to create a working solution for the previously described MessageBox scenario and a simple Windows.Forms app. I will post the steps to reproduce the work around next week.
Comment 11 Gordon 2012-10-17 18:14:11 UTC
Any news on this, I've got a big app waiting to distribute?
Comment 12 Joachim Graesser 2012-10-18 04:56:02 UTC
Gordon,

in case your request references to my post above: 

I'm currently struggling getting our own big solution running. It uses X11 server and OpenTK, so it's a little more complicated than the HelloWorld MessageBox ;) Will provide the solution as soon as I have found it, here.

Joachim
Comment 13 Gordon 2012-10-19 03:28:12 UTC
It's for anybody. It seems I can't use System.Drawing in my app because it can't be packaged properly.
This is pretty miserable for me, I've spent a long time creating this and it contains a lot of very involved image processing which I don't really want to start converting to core graphics. I've tried copying lots of different libraries to the monobundle folder in the .app but it has no effect. I don't know how you guys are managing to get error logs from the app, mine just crashes every time it meets a system.drawing reference. I've very down about this. :(
Comment 14 Sebastien Pouliot 2013-01-02 12:05:41 UTC
The new version of MMP shipped with Xamarin.Mac [1] is, among other things, quite a bit smarter about native library dependencies. 

E.g. it will pick up the required native libraries for any assembly (like System.Drawing or Mono.Posix) and, recursively, other libraries that they also require.

That should cover the case described above - without adding unrequired (or duplicated with the OS) libraries inside your app bundles. If there's still an issue then please open a bug (Xamarin.Mac product) with a test case and we'll fix this asap (i.e. it's a supported product now).

[1] http://xamarin.com/mac
Comment 15 tadaP 2013-01-10 15:49:17 UTC
I am facing the error System.Drawing.GDIPlus not found even though the file libgdiplus.dylib is available @ 

/Library/Frameworks/Mono.framework/Versions/2.10.9/lib

while dropping a file built in Windows and dropped in MAC.

MemoryStream imageStream = new MemoryStream(imageData);
System.Drawing.Image screenImage = Bitmap.FromStream(imageStream, true, true);
screenImage.Save(screenShotPath, ImageFormat.Jpeg);

At the same time while building the same app in MAC and launching all the above steps work just fine.

Any pointers would be appreciated!!!!
Comment 16 Sebastien Pouliot 2013-01-10 16:45:27 UTC
@tadaP if you're using Xamarin.Mac then please open a new bug report (on this product) and specifiy how you created the application (e.g. if you were using mmp, embedding the mono runtime, with your application or not).