I have used every time “system.drawing.common” and it works as expected on my Windows machine. Publish this web application on Windows-based Azure App Service everything works great.
After some while, I want to use this part in an Azure App-Service, but on Linux and it does not work 😦
This was the Exception
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception
System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies
At this time I was shocked because I hadn’t expected this.
What options I had:
- switch back to windows
- Host the app in Linux docker and add this package
- use an Alternative Libary
Option 1 was not an option, because I like running this code on Linux.
So I tried the 2nd option Add docker-compose to Visual Studio and I got the same error because it’s based on docker image “microsoft/dotnet:runtime” and there is also the libraries missing
libc6-dev
libgdiplus libx11-dev
At this point, I did not want to generate an Azure Container Registry or search on Github. I like the easy deployment in Azure and I want to use it as PAAS.
I know Azure App Service for Linux is a docker container based on “TODO”, but I prefer the basic Azure Services because Microsoft makes a great job to run the Infrastructure and it is cheaper 🙂
So I looked at alternatives i found SixLabors/ImageSharp and i tried it. After 20 min all System.drawing.common was removed and replaced with the new one.
and it worked as expected.
Conclusion:
Linux and Windows are different.
I will never say again:
It’s dotnet core it will run on Linux and windows
because it’s not every time true.
But for the next project, I would do it in the same way, because I look for a library first from the Framework creator