Reputation: 2008
Posting this question for others experiencing the same issue. My answer below.
I created an AWS Lambda method that receives a series of query parameters that are used to produce a report. The report data is saved in an Excel file using the excellent EPPlus library. When I run the code in the development environment it executes without a problem. After I deploy the code to AWS and call it via the URL I get the following exception:
The type initializer for 'Gdip' threw an exception
Why would this happen after deployment, yet run properly in the development environment?
Upvotes: 2
Views: 409
Reputation: 5486
I believe that this is now fixed - https://github.com/EPPlusSoftware/EPPlus/issues/495
Fixed in 6.0.3. EPPlus will no longer need System.Drawing.Common, as native support for images and autofit columns has been implemented. System.Drawing.Common can still be used via the EPPlus.System.Drawing for supported environments.
Upvotes: 1
Reputation: 2008
What I was able to determine is that the error occurs when attempting to automatically size column widths to fit the supplied data in one of the worksheets. EPPlus helpfully supplies an AutoFitColumns
method for a range that will size the columns based on the widest data in the range. Once I pinpointed this line of code as the source of the exception it all made sense.
I have not confirmed this, but I assume that EPPlus loops through the text in each cell of the range and calls the .Net Graphics.MeasureString method from the System.Drawing namespace to determine the width of the rendered text. Once the widest string is determined the column width is set accordingly.
The problem is that it appears that the GDI+ API is not available in the AWS lambda environment. I believe you can add libgdiplus
to your AWS Lambda environment (see forum discussions here and here). However, I did not attempt to change my configuration, instead opting for default column widths with word wrap enabled.
Upvotes: 2