Runtime: dotnet not longer load dylib from $HOME/lib after upgrade to 3.1.2

Created on 27 Feb 2020  Â·  16Comments  Â·  Source: dotnet/runtime

After upgrade to dotnet 3.1.2, I found dotnet run no longer work with Drawing.Common and libgdiplus installed to $HOME/lib
System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibgdiplus, 1): image not found at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)

Now, it only tries to load the library from the followings,

  1. /usr/lib
  2. /usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.2/liblibgdiplus.dylib
  3. project root folder where dotnet run was launched
area-Interop-coreclr untriaged

Most helpful comment

Linking libgdiplus.dylib (installed with brew install mono-libgdiplus) worked, thanks!

sudo ln -s /usr/local/lib/libgdiplus.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.2

Beware: this trick will only work during development, publishing a self-contained app (with dotnet publish --self-contained --runtime osx-x64) will not copy the libgdiplus.dylib file, it will still be loaded from /usr/local/lib/libgdiplus.dylib at runtime. (I checked with DYLD_PRINT_LIBRARIES=1 ./MyDotNetCoreApp)

All 16 comments

`dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.102
Commit: 573d158fea

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.102/

Host (useful for support):
Version: 3.1.2
Commit: 916b5cba26

.NET Core SDKs installed:
2.1.803 [/usr/local/share/dotnet/sdk]
2.2.402 [/usr/local/share/dotnet/sdk]
3.0.102 [/usr/local/share/dotnet/sdk]
3.1.102 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
`

The following code with xcode runs fine,
let h = dlopen("libgdiplus", 1) if h != nil { print("not able to load libgdiplus") } else { print("libgdiplus is loaded") }

@andy-yx-chen can you try running this with an apphost?
<PropertyGroup> <UseAppHost>true</UseAppHost> </PropertyGroup>
We just got .NET Core into a notarized package and you may be running into a limitation of the default entitlements that we provided on ./dotnet.
https://docs.microsoft.com/en-us/dotnet/core/install/macos-notarization-issues

@jeffschwMSFT Neat! thanks, that works and the change makes a lot of sense, thank you!

I run into the same issue, and following fix did not help.

 System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibgdiplus, 1): image not found
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
   at System.Drawing.SafeNativeMethods.Gdip..cctor()

If I run

$ ls /usr/local/lib

I see that library is there.
Probably, because I'm trying to debug from rider? Could you advice what else I can possibly be missing or where else to look?

For dotnet , the solution does not work, I think that should be fixed, for my devbox, I just go with link the dylib to dotnet core app share, such as /usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.2

Yeah I done the same - it did not help :/

that works for me, or you can try fs_usage and check which paths were searched by your app

Nevermind, I added it to Microsoft.AspNETCore.App. Works, thanks @andy-yx-chen !

Linking libgdiplus.dylib (installed with brew install mono-libgdiplus) worked, thanks!

sudo ln -s /usr/local/lib/libgdiplus.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.2

Beware: this trick will only work during development, publishing a self-contained app (with dotnet publish --self-contained --runtime osx-x64) will not copy the libgdiplus.dylib file, it will still be loaded from /usr/local/lib/libgdiplus.dylib at runtime. (I checked with DYLD_PRINT_LIBRARIES=1 ./MyDotNetCoreApp)

Can confirm this bug happens on Catalina using .net Core 3.1.3

For 3.1.3 we can follow the advice from @0xced and bump the version to 3.1.3:

sudo ln -s /usr/local/lib/libgdiplus.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.3

This worked on _on my machine._

Also for .NET 5.0-Preview 1, @0xced trick solves to issue.

sudo ln -s /usr/local/lib/libgdiplus.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/5.0.0-preview.1.20120.5/

Same thing for idnkitlite broken:
√% sudo ln -s /usr/local/lib/libidnkitlite.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.2.7/
√% sudo ln -s /usr/local/lib/libidnkitlite.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.6

Thanks @andy-yx-chen and @0xced! Your solution worked. I installed the library through Homebrew and then linked the file. You're a star.

For System.Drawing.Common on macOS, there is another solution that doesn't need updating the symbolic link with each .NET Core update. @quamotion published a NuGet package that bundles all the required native libraries: runtime.osx.10.10-x64.CoreCompat.System.Drawing.

To use it, just add a package reference in your project file and libgdiplus.dylib will automatically be available. Note that this solution (unlike the symlink trick) works with self-contained app publishing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sahithreddyk picture sahithreddyk  Â·  3Comments

omajid picture omajid  Â·  3Comments

GitAntoinee picture GitAntoinee  Â·  3Comments

jamesqo picture jamesqo  Â·  3Comments

omariom picture omariom  Â·  3Comments