Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
oguzhantopcu opened this issue May 17, 2019 · 54 comments
Closed

Comments

@oguzhantopcu
Copy link

oguzhantopcu commented May 17, 2019

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
Copy link

You can try

sudo apt install libc6-dev 
sudo apt install libgdiplus

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

@karelz
Copy link
Member

karelz commented May 17, 2019

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

cc @safern

@karelz karelz closed this as completed May 17, 2019
@karelz
Copy link
Member

karelz commented May 17, 2019

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

@safern
Copy link
Member

safern commented May 17, 2019

Thanks for replying @igoventura

@oguzhantopcu
Copy link
Author

oguzhantopcu commented May 17, 2019

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
Copy link
Member

safern commented May 17, 2019

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
Copy link

sxtfv commented Jun 4, 2019

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
Copy link
Author

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
Copy link
Author

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

@safern
Copy link
Member

safern commented Jun 11, 2019

@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
Copy link
Author

oguzhantopcu commented Jun 11, 2019

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
Copy link
Member

safern commented Jun 11, 2019

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
Copy link
Member

safern commented Jun 11, 2019

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: mono/libgdiplus#546

@oguzhantopcu
Copy link
Author

oguzhantopcu commented Jun 11, 2019

@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
Copy link
Member

safern commented Jun 12, 2019

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
Copy link

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

@khanghyxda
Copy link

image

@oguzhantopcu
Copy link
Author

@khanghyxda

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

@TraceLD
Copy link

TraceLD commented Jul 26, 2019

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
Copy link

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

@zzzzz00000
Copy link

zzzzz00000 commented Aug 19, 2019

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
Copy link

msx752 commented Aug 29, 2019

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

@joalcava
Copy link

joalcava commented Sep 20, 2019

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

@safern
Copy link
Member

safern commented Sep 20, 2019

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
Copy link

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
Copy link
Member

safern commented Sep 20, 2019

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
Copy link

@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!.

@amirvenus
Copy link

brew install mono-libgdiplus

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

@fjod
Copy link

fjod commented Nov 25, 2019

I had same problem in gitlab pipeline, so I added

  • "apt-get update -qq && apt-get install -y libc6-dev libgdiplus"

and it helped

@msx752
Copy link

msx752 commented Dec 8, 2019

this solved my issue on .NET Core 3.1

  • apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev

@mkdior
Copy link

mkdior commented Dec 8, 2019

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
Copy link

fuffu commented Dec 12, 2019

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
Copy link

Binb1 commented Feb 1, 2020

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
Copy link

hypertrends commented Feb 18, 2020

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
Copy link

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
Copy link

ogg130 commented Mar 2, 2020

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
Copy link

Andotnet commented Mar 3, 2020

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

@eduardoluizm
Copy link

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
Copy link

Faeinc commented Mar 15, 2020

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

@aseemgautam
Copy link

@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
Copy link

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
Copy link

naouaro commented Apr 27, 2020

On macOS Catalina, VSCode 1.44.2

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

@leopignataro
Copy link

leopignataro commented Apr 30, 2020

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:

  • Why install apt-utils?
  • How big of a performance hit will this cause (especially considering the apt-get update)?

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
Copy link

pmamcdk commented May 28, 2020

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
Copy link

dpeiris commented Jun 4, 2020

pmamcdk - Thanks and your post really saved my day.

@tmutton
Copy link

tmutton commented Jun 28, 2020

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
Copy link

rogatec commented Aug 6, 2020

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

@ntamvl
Copy link

ntamvl commented Aug 21, 2020

brew install mono-libgdiplus

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

It works!
Thank you

@cretumarius
Copy link

brew install mono-libgdiplus

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

It worked for me on macOS Catalina 10.15.4 as well.
Thank you!

@leopignataro
Copy link

Here's my two cents: this used to be a problem for me on Azure App Services running on Linux. I solved it adding the "apt-get ... && apt-install ..." line as suggested on previous posts. However, sometime around Oct/Nov of 2020, this stopped being an issue. I no longer need to add anything on the Startup command, it just works.

Perhaps there was some kind of change on the underlying Azure infrastructure... It remains a mistery to me why this was an issue in the first place for so many people.

@cdavidyoung
Copy link

cdavidyoung commented Jan 12, 2023

The comment by @pmamcdk above fixed my problem on Mac. Need to install the "runtime.osx.10.10-x64.CoreCompat.System.Drawing" by the build in nuget manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests