We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PptxReadException: The Type Initializer for 'Gdip' Threw an Exception

I am writing an AWS lambda function in C# .NET Core 3.1. I am reading a ppt file as stream and passing this stream to Aspose.Slides.Presentation to get the slides. I am using Aspose.Slides.NET (21.11.0) package.

The lambda function code is:

public async Task<bool> FunctionHandler(Params obj, ILambdaContext context)
        {
            var accessKey = System.Environment.GetEnvironmentVariable("AwsAccessKeyId");
            var secretKey = System.Environment.GetEnvironmentVariable("AwsSecretAccessKey");
            var region = System.Environment.GetEnvironmentVariable("Region");
            _logger = context.Logger;

            _logger.LogLine($"{LambdaName} process started");
            try
            {
                using (var client = new AmazonS3Client(accessKey, secretKey, RegionEndpoint.GetBySystemName(region)))
                {
                    var stream = await ReadFile(obj.bucketName, obj.keyName + @"/" + obj.uploadedPPTName, client);
                    _logger.LogLine($"File has been read as stream : Stream length : { stream.Length}");
                    Presentation presentation = new Presentation(stream);
                    var imagePrefix = obj.uploadedPPTName.Split('.')[0];
                    for (var index = 0; index < presentation.Slides.Count; index++)
                    {
                        ISlide slide = presentation.Slides[index];

                        Stream imageslideStream = new System.IO.MemoryStream();

                        var bitmap = slide.GetThumbnail(1f, 1f);
                        bitmap.Save(imageslideStream, ImageFormat.Png);
                        await WriteStreamFileToS3(obj.bucketName, obj.keyName, imageslideStream, $"{imagePrefix}-slide-{index + 1}", client);
                    }
                }
            }
            catch(Exception ex)
            {
                _logger.LogLine($"An error occurred in FunctionHandler of {LambdaName} : {ex.ToString()}");
                return false;
            }

            return true;
        }

This lambda function is working fine on windows machine but when i publish this lambda function to AWS and run it, i get the following error:

START RequestId: 97efe54c-1f35-41c3-aee3-9811bca0c6ed Version: $LATEST
PowerPointProcessorLambda process started
File has been read as stream : Stream length : 2786125
Ann error occurred in FunctionHandler of PowerPointProcessorLambda : Aspose.Slides.PptxReadException: The type initializer for 'Gdip' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibgdiplus: cannot open shared object file: No such file or directory
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
   at System.Drawing.SafeNativeMethods.Gdip..cctor()
   --- End of inner exception stack trace ---
   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.InitializeFromStream(Stream stream)
   at System.Drawing.Image.LoadFromStream(Stream stream, Boolean keepAlive)
   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
   at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
   at System.Drawing.Image.FromStream(Stream stream)
   at Aspose.Slides.ImageCollection.(    )
   at  .(    )
   at   .(    )
   at   ​.(    , IPresentation )
   at   ​.(Presentation , Stream , InterruptionToken )
   --- End of inner exception stack trace ---
   at   ​.(Presentation , Stream , InterruptionToken )
   at Aspose.Slides.Presentation.(Stream , Boolean )
   at Aspose.Slides.Presentation.(Stream , Boolean )
   at Aspose.Slides.Presentation.(Stream )
   at Aspose.Slides.Presentation..ctor(Stream stream)
   at Opus.Lambda.PowerPointProcessor.Function.FunctionHandler(Params obj, ILambdaContext context) in D:\Projects\Code\Lambda.PowerPointProcessor\Function.cs:line 46
END RequestId: 97efe54c-1f35-41c3-aee3-9811bca0c6ed
REPORT RequestId: 97efe54c-1f35-41c3-aee3-9811bca0c6ed	Duration: 8625.27 ms	Billed Duration: 8626 ms	Memory Size: 256 MB	Max Memory Used: 148 MB	Init Duration: 159.91 ms	

This error is occurring at line Presentation presentation = new Presentation(stream); of lambda function.

I also tried using the CoreCompat.System.Drawing (1.0.0-beta006) package but still got the same error.

How can this error be resolved? Any help would be much appreciated.

@Waleed_Naveed,
Welcome to our community! Thank you for contacting support.

It looks like libgdiplus library has not been installed on the operating system on which the code example runs. Please check this carefully. Also, please check if System.Drawing.Common 5.0.3 is included in your app project.

After that, if the issue persists, please share and specify the following:

  • input presentation file
  • OS version on which the error occurs