Skip to content
Petkir Blog
XLinkedinBluesky

Navigating Image Manipulation in dotnet core and Azure App Service (Linux)

Code, Linux, C#, Docker1 min read

In the world of web development, image manipulation is a common necessity. Whether it's resizing images for thumbnails or applying filters for aesthetic enhancements, developers often rely on libraries like System.Drawing.Common in their dotnet core applications to handle such tasks seamlessly. However, what happens when you transition your application from a Windows-based Azure App Service to a Linux environment? That's where the journey through the nuances of platform compatibility begins.

The Transition

Imagine this scenario: you've developed an application using System.Drawing.Common, and it works flawlessly on your Windows machine. Deployment to a Windows-based Azure App Service is smooth sailing, and everything functions as expected. But then comes the twist - you decide to migrate your application to an Azure App Service running on Linux. Suddenly, you're faced with unexpected errors.

System.TypeInitializationException: The type initializer for 'Gdip' threw an exception
System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies

The shock of encountering these errors highlights a crucial point: Linux and Windows environments are not identical, especially when it comes to dependency management and library support.

Exploring Options

Faced with this dilemma, you evaluate your options:

  1. Switch back to Windows: While this may seem like a quick fix, it goes against your preference for running your code on Linux.
  2. Utilize Docker: Hosting your application in a Linux docker container seems promising. However, even with docker-compose in Visual Studio, you encounter similar dependency issues due to missing libraries (libc6-dev, libgdiplus, libx11-dev).
  3. Explore Alternative Libraries: This path leads you to discover SixLabors/ImageSharp, a promising alternative to System.Drawing.Common. With ImageSharp, you find that after a mere 20 minutes, you successfully replace all references to System.Drawing.Common, and your application runs smoothly once again.