dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
20.95k stars 4.9k forks source link

Unable to load DLL 'libgdiplus': The specified module could not be found. #2746

Closed oguzhantopcu closed 5 years ago

oguzhantopcu commented 5 years ago

I can not use GDI+ related things on Fedora 30. I am getting an error while calling Image.FromStream(ms).

Error & stacktrace:

System.TypeInitializationException : The type initializer for 'Gdip' threw an exception.
---- System.DllNotFoundException : Unable to load DLL 'libgdiplus': The specified module could not be found.
   at System.Drawing.SafeNativeMethods.Gdip.GdipLoadImageFromDelegate_linux(StreamGetHeaderDelegate getHeader, StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr& image)
   at System.Drawing.Image.InitFromStream(Stream stream)
   at System.Drawing.Image.LoadFromStream(Stream stream, Boolean keepAlive)
   at Pompa.Invoicing.Xslt.ImageUtility.Resize(Byte[] image, Int32 width, Int32 height) in /home/j/Projects/pompa/src/Pompa.Invoicing/Xslt/ImageUtility.cs:line 15
   at Pompa.Invoicing.Xslt.XsltGenerator.GetEArchive(Byte[] signature, DiscountType discountType, Byte[] logo) in /home/j/Projects/pompa/src/Pompa.Invoicing/Xslt/XsltGenerator.cs:line 41
   at Pompa.Business.Tests.Gib.FakeInvoiceGeneratorBase.GenerateXslt(Boolean eb, DiscountType discountType) in /home/j/Projects/pompa/src/Pompa.Business.Tests/Gib/FakeInvoiceGeneratorBase.cs:line 137
   at Pompa.Business.Tests.Gib.FakeInvoiceGeneratorBase.GenerateArchiveUbl(DiscountType discountType) in /home/j/Projects/pompa/src/Pompa.Business.Tests/Gib/FakeInvoiceGeneratorBase.cs:line 116
   at Pompa.Business.Tests.Gib.GibProxyFacts`2.CreateArchiveInvoice(DiscountType discountType) in /home/j/Projects/pompa/src/Pompa.Business.Tests/Gib/GibProxyFacts.cs:line 47
   at Pompa.Business.Tests.Gib.GibProxyFacts`2.GetArchivePDF_Should_Get(DiscountType discountType) in /home/j/Projects/pompa/src/Pompa.Business.Tests/Gib/GibProxyFacts.cs:line 111
--- End of stack trace from previous location where exception was thrown ---
----- Inner Stack Trace -----
   at System.Runtime.InteropServices.FunctionWrapper`1.get_Delegate()
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
   at System.Drawing.SafeNativeMethods.Gdip..cctor()

My setup Fedora 30 .Net Core 2.2.204 libgdiplus-devel 5.6-3.fc30 libgdiplus 5.6-3.fc30 Linux x 5.0.13-300.fc30.x86_64 #1 SMP Mon May 6 00:39:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

igoventura commented 5 years ago

You can try

sudo apt install libc6-dev 
sudo apt install libgdiplus

or https://github.com/mono/libgdiplus

karelz commented 5 years ago

Looks answered. Feel free to reopen if you need more help.

cc @safern

karelz commented 5 years ago

Thanks @igoventura for your help on multiple issues here! It's appreciated!

safern commented 5 years ago

Thanks for replying @igoventura

oguzhantopcu commented 5 years ago

libgdiplus is already installed on my computer. I have already shared my version numbers.

I have just tried compiling/installing libgdiplus from the source code. it did not worked. I still get the same error.

I think I have no right to re-open the issue. so it is up to you.

safern commented 5 years ago

libc6-dev

did you install libc6-dev as well? It is required by libgdiplus

Also could you please try setting: LD_LIBRARY_PATH env variable to point to the location of libgdiplus.

Also you can use LD_DEBUG to find out which library it is actually not finding, because even though you have libgdiplus you could be missing a dependency like libc6-dev which would cause the load to fail.

http://www.bnikolic.co.uk/blog/linux-ld-debug.html

sxtfv commented 5 years ago

Hello, I am using Fedora 30 and .net core 2.1 and I have exactly the same issue. I can see you suggest to install libc6-dev, but it's not available for Fedora. What I have installed is: glibc, glibc-devel, glibc-devel.i686, libgdiplus, libX11-devel, but it still doesn't work. Which packages should be installed to make it work on Fedora?

oguzhantopcu commented 5 years ago

I have installed all libraries you have suggested. I also downloaded libgdiplus source then compiled/installed myself. did not work.

I set env variable as you specified. Same error.

image

I have tried to use LD_DEBUG, I could not investigate anything since it is giving an output like a matrix (movie) window.

Alsı I have failed to redirect LD_DEBUG output to a file ">" or | tee is not working.

oguzhantopcu commented 5 years ago

Is it possible to re-open this issue since it is not resolved actually? @karelz

safern commented 5 years ago

@oguzhantopcu could you please run find -name libgdiplus* on your computer?

Try linking /usr/lib64/ to /usr/lib/.

Also, it would be great if you could share LD_DEBUG output. That would really help me understand where the runtime is trying to load libgdiplus from.

EDIT: I didn't see that you tried to use LD_DEBUG when initially commented. Did you try setting a LD_DEBUG value for libraries only?

i.e: export LD_DEBUG=libs dotnet test ...

oguzhantopcu commented 5 years ago

find gives nothing but locate libgdiplus gives following

/usr/lib64/libgdiplus.so
/usr/lib64/libgdiplus.so.0
/usr/lib64/libgdiplus.so.0.0.0
/usr/lib64/pkgconfig/libgdiplus.pc
/usr/local/lib/libgdiplus.a
/usr/local/lib/libgdiplus.la
/usr/local/lib/libgdiplus.so
/usr/local/lib/libgdiplus.so.0
/usr/local/lib/libgdiplus.so.0.0.0
/usr/local/lib/pkgconfig/libgdiplus.pc
/usr/share/doc/libgdiplus
/usr/share/doc/libgdiplus/AUTHORS
/usr/share/doc/libgdiplus/ChangeLog
/usr/share/doc/libgdiplus/NEWS
/usr/share/doc/libgdiplus/README
/usr/share/doc/libgdiplus/TODO
/usr/share/licenses/libgdiplus
/usr/share/licenses/libgdiplus/COPYING

what I have tried:

export LD_LIBRARY=/usr/lib/; dotnet test Pompa.Business.Tests.csproj --filter "FullyQualifiedName~Invoice_Cast"

export LD_LIBRARY=/usr/lib64/; dotnet test Pompa.Business.Tests.csproj --filter "FullyQualifiedName~Invoice_Cast"

export LD_LIBRARY=/usr/local/lib/; dotnet test Pompa.Business.Tests.csproj --filter "FullyQualifiedName~Invoice_Cast"

export LD_DEBUG=libs; dotnet test Pompa.Business.Tests.csproj --filter "FullyQualifiedName~Invoice_Cast"

The last one gives HUGE output, I can not examine it nor copy from the console. I can not redirect the output to the text file neither. ">" or | tee is not doing the trick.

safern commented 5 years ago

can you do the last one and grep for libgdiplus?

export LD_DEBUG=libs; dotnet test Pompa.Business.Tests.csproj --filter "FullyQualifiedName~Invoice_Cast" | grep libgdiplus

safern commented 5 years ago

Also, do you have: glibc-locale-source installed?

Btw, I'd like to mention that we just found out that libgdiplus is not working on Fedora30 because one of its dependencies did a breaking change making an API private which they use. So it fails with: symbol lookup error: /lib64/libgdiplus.so.0: undefined symbol: GifQuantizeBuffer

I've started a thread with them and also have tracking issue: https://github.com/mono/libgdiplus/issues/546

oguzhantopcu commented 5 years ago

@safern grep is not working with LD_DEBUG. it gives all the output without any filtering, nor >, | tee are working.

BTW I am using fedora 30 :).

safern commented 5 years ago

Ok, so I got a local repro, used LD_DEBUG=libs and then found the error. The loader is hitting a fatal error when trying to load libgdiplus because of the issue I pointed above that GifQuantizeBuffer no longer exists on Fedora30. So this is a libgdiplus issue, I've contacted them via email and also pinged them on the issue above. Sorry for the headaches, and your setup seems correct, however our error is not ideal. We do have an issue in corefx to improve that error: https://github.com/dotnet/corefx/issues/37260

/lib64/libgdiplus.so.0: error: symbol lookup error: undefined symbol: GifQuantizeBuffer (fatal)

/lib64/libgdiplus.so.0: error: symbol lookup error: undefined symbol: GifQuantizeBuffer (fatal)
      1150:     find library=libgdiplus.so [0]; searching
      1150:      search cache=/etc/ld.so.cache
      1150:      search path=/lib64/tls:/lib64:/usr/lib64/tls:/usr/lib64                (system search path)
      1150:       trying file=/lib64/tls/libgdiplus.so
      1150:       trying file=/lib64/libgdiplus.so
      1150:       trying file=/usr/lib64/tls/libgdiplus.so
      1150:       trying file=/usr/lib64/libgdiplus.so
khanghyxda commented 5 years ago

Installed libc6-dev & libgdiplus but still error. Ubuntu 16.03. Please re open this issue.

khanghyxda commented 5 years ago

image

oguzhantopcu commented 5 years ago

@khanghyxda

You can fix the problem by installing System.Drawing.Common 4.6.0-preview.

TraceLD commented 5 years ago

Use 4.6.0-preview7.19362.9 version of System.Drawing.Common like so: <PackageReference Include="System.Drawing.Common" Version="4.6.0-preview7.19362.9" /> to fix the issue.

WinderBless commented 5 years ago

i meet the same error, after i updata System.Drawing.Common to 4.6.0-preview it`s okay~~

zzzzz00000 commented 5 years ago

I have same error. It is not working with "4.5.1", it is not working with "4.6.0-preview8.19405.3". But working with "4.6.0-preview7.19362.9".

msx752 commented 5 years ago

.net core 3 preview8 has different issue such as non displaying text which drawing on bitmap. it shows empty square

joalcava commented 5 years ago

Still an error in Ubuntu 19.04 using .net core 3 rc1, I have tried everything that is said in this issue.

safern commented 5 years ago

Still an error in Ubuntu 19.04 using .net core 3 rc1, I have tried everything that is said in this issue.

could you please share what version of the S.D.Common package and what target framework did you use?

joalcava commented 5 years ago

could you please share what version of the S.D.Common package and what target framework did you use?

Hi @safern, <TargetFramework> is: netcoreapp3.0, I'm not referencing S.D.C directly because I'm using a library call EPPlus, It seems like they are using 4.5.1

safern commented 5 years ago

I see, that is the problem. We fixed the way we're hooking up the native loading of the dependencies to make it better, so you would need to use a System.Drawing.Common that is >= 4.6.0, would you mind trying to add a PackageReference to S.D.Common, with version 4.6.0-rc1 and validating if you still hit the issue? (If you're consuming their library through package reference as well, your reference would win, and you would use the latter).

joalcava commented 5 years ago

@safern Thank you! You saved my day, I had tried that before but with the preview6 version of the package and it didnt work, now it does with the rc1!.

safern commented 5 years ago

now it does with the rc1!.

Great to hear! Yeah, the fixes we made on the native loading were after preview6, happy we could actually made them to the final release for people to stop hitting this issues, let me know if something else shows up 😄

dstj commented 5 years ago

Is there a way to make it work without installing libc6-dev?

I ask because I'm hosting on Heroku and the latest stack "Heroku-18" no longer allows libc6-dev at runtime (see this page) and I'm back with the error Unable to load DLL 'libgdiplus': The specified module could not be found. :/

Note: I also created this StackOverflow post to try to get a workaround/hack/fix.

turric4n commented 5 years ago

Dudes, why not work with containers?

https://gist.github.com/turric4n/d00ad299a4c70656b562ce0fb11aab6d.js

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-disco EXPOSE 80/tcp WORKDIR /app COPY . ./ RUN apt-get update && apt-get install -y \ libc6-dev \ libgdiplus \ && rm -rf /var/lib/apt/lists/* ENTRYPOINT [ "dotnet", "lib.dll" ]

amirvenus commented 4 years ago

brew install mono-libgdiplus

I am on my macOS Mojave and that seemed to be doing the trick for me

fjod commented 4 years ago

I had same problem in gitlab pipeline, so I added

and it helped

msx752 commented 4 years ago

this solved my issue on .NET Core 3.1

mkdior commented 4 years ago

brew install mono-libgdiplus

I am on my macOS Mojave and that seemed to be doing the trick for me

Can confirm that this fixes the issue on Mojave.

fuffu commented 4 years ago

How can I fix this issue on .NET Core 3.1 hosted on Linux Azure App Service? I have the latest System.Drawing.Common 4.7.0 installed.

Binb1 commented 4 years ago

How can I fix this issue on .NET Core 3.1 hosted on Linux Azure App Service? I have the latest System.Drawing.Common 4.7.0 installed.

Any update on this ?

hypertrends commented 4 years ago

Hello, I am facing the exact same issue as well. We are on .NET Core 3.1, have the latest System.Drawing.Common 4.7.0 installed but when we try to deploy this to Linux Azure App Service, we face the exact same issue. None of the above mentioned solutions seem to be working. I am chatting with Azure Support and they are looking into a solution. Any help would be very much appreciated.

atrueresistance commented 4 years ago

Like @msx752 stated, apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev has to be ran. The issue I ran into was the same as @Binb1 where I have 3.1 installed and running on a ubuntu server with System.Drawing.Common 4.7.0 nuget package. If you change the package to include the prerelease 4.7.0-preview3.19551.4 solved my issue.

ogg130 commented 4 years ago

back in dotnetcore 2.2, I had to use this process to add all of the necessary libraries to my container so that it would work with system.drawing. This may have to be updated for 3.1. I'm actually working on this today for 3.1 so ill provide any updated instructions as I find them:

1) docker pull ubuntu

2) docker run -t ubuntu:latest /bin/bash -> to open a container shell ->

3) apt-get update apt

4) apt-get install wget

5) wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

6) dpkg -i packages-microsoft-prod.deb

7) apt-get install apt-transport-https

8) apt-get update

9) apt-get install dotnet-sdk-2.2 <---- this will need to change for sure

10) apt-get install libgdiplus

11) cd /usr/lib

12) ln -s libgdiplus.so gdiplus.dll

13) apt-get install libc6-dev libx11-dev

14) rm -rf /var/lib/apt/lists/*

Andotnet commented 4 years ago

Just add
runtime.osx.10.10-x64.CoreCompat.System.Drawing nuget package

eduardoluizm commented 4 years ago

On Linux Azure App Service, you can do this:

image

Just insert the code below on "Startup command" changing the dll name.

apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev && dotnet YourWebSite.dll

this solved my issue!

Faeinc commented 4 years ago

This did not work for me. Anyone else have other solutions?

aseemgautam commented 4 years ago

@Andotnet thanks, it worked for me.

I had mono-libgdiplus installed & everything was working fine. Strange but updating VS on osx triggered this issue.

Referencingruntime.osx.10.10-x64.CoreCompat.System.Drawing fixed it.

Bruno2049 commented 4 years ago

brew install mono-libgdiplus

I am on my macOS Mojave and that seemed to be doing the trick for me

@amirvenus that solve the problem, thanks

naouaro commented 4 years ago

On macOS Catalina, VSCode 1.44.2

nuget -> "runtime.osx.10.10-x64.CoreCompat.System.Drawing" fixed the problem

leopignataro commented 4 years ago

On Linux Azure App Service, you can do this:

image

Just insert the code below on "Startup command" changing the dll name.

apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev && dotnet YourWebSite.dll

this solved my issue!

This, too, solved by problem on an Azure App Service running on Linux, thank you @eduardoluizm

Two questions, tough:

And perhaps the biggest question of all: is this a .NET Core bug? Or perhaps a problem with the Docker image, that should have these packages installed? I see a huge variety of platform-specific solutions on this thread, but are we really supposed to need these workarounds in the first place?

pmamcdk commented 4 years ago

Had the same problem on my mac in visual studio 2019. Installed mono-libgdiplus with brew but this wasn't enough. Read many articles, but some how no one mention that you with visual studio for mac also need to install the "runtime.osx.10.10-x64.CoreCompat.System.Drawing" by the build in nuget manager. After this it's working. Hopefully this will help others save some time. Thank you naouaro for giving me the hint. BR

dpeiris commented 4 years ago

pmamcdk - Thanks and your post really saved my day.

tmutton commented 4 years ago

On Linux Azure App Service, you can do this:

image

Just insert the code below on "Startup command" changing the dll name.

apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev && dotnet YourWebSite.dll

this solved my issue!

This worked for me. Thank You.

rogatec commented 4 years ago

On Linux Azure App Service, you can do this:

image

Just insert the code below on "Startup command" changing the dll name.

apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev && dotnet YourWebSite.dll

this solved my issue!

I can confirm this works also if using Bitbucket pipelines. Just add as a first step in your script:

script:
  - apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
  - dotnet restore