Skip to content

ERROR:The type initializer for 'Gdip' threw an exception on Ubunto server #27200

@softsan

Description

@softsan

Tried using System.Drawing.Common package for my .net core web api project. It runs fine under windows but on ubunto (which is my host server), it throws following errors:
This is the method i used to generate thumbnail:

public static bool CreateThumbnail(int Width, int Height, Stream filePath, string saveFilePath)
        {

            try
            {
                var byteArray = filePath;  
                var streamImg = Image.FromStream(byteArray);

                Bitmap sourceImage = new Bitmap(streamImg);
                using (Bitmap objBitmap = new Bitmap(Width, Height))
                {
                    objBitmap.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
                    using (Graphics objGraphics = Graphics.FromImage(objBitmap))
                    {
                        // Set the graphic format for better result cropping   
                        objGraphics.SmoothingMode = SmoothingMode.HighQuality;
                        objGraphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
                        objGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        objGraphics.CompositingQuality = CompositingQuality.HighQuality;
                        objGraphics.DrawImage(sourceImage, 0, 0, Width, Height);

                        // Save the file path, note we use png format to support png file   
                        objBitmap.Save(saveFilePath);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log("Create Thumbnail: ERROR:" + ex.Message + "\n" + ex.StackTrace);
                return false;
            }
            return true;
        }
ERROR:The type initializer for 'Gdip' threw an exception.
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)

Already installed
sudo apt-get install libgdiplus
and did this too:

cd /usr/lib
sudo ln -s libgdiplus.so gdiplus.dll

So Any workaround or thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions