Unable to load DLL 'libgdiplus': The specified module could not be found.
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
You can try
sudo apt install libc6-dev
sudo apt install libgdiplus
or https://github.com/mono/libgdiplus
Looks answered. Feel free to reopen if you need more help.
cc @safern
Thanks @igoventura for your help on multiple issues here! It's appreciated!
Thanks for replying @igoventura
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.
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
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?
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.

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.
Is it possible to re-open this issue since it is not resolved actually? @karelz
@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 ...
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.
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
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
@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 :).
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
Installed libc6-dev & libgdiplus but still error. Ubuntu 16.03. Please re open this issue.

@khanghyxda
You can fix the problem by installing System.Drawing.Common 4.6.0-preview.
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.
i meet the same error, after i updata System.Drawing.Common to 4.6.0-preview it`s okay~~