0

I was trying to add System.Drawing library inside a lambda function using container image. Followed the AWS documentation here

Added

RUN yum install -y amazon-linux-extras 
RUN amazon-linux-extras install epel -y
RUN yum install -y libgdiplus  

Inside the Dockerfile.

while calling the lambda i am getting an error

System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.

sachin mathew
  • 1,432
  • 11
  • 19
  • I don't see a question here. But as the error mention indicates, System.Drawing isn't supported on non-Windows platforms. Lambda is a non-Windows platform, so unfortunately you can not use the System.Drawing library in a Lambda function. I believe Microsoft is working on something to get System.Drawing (or a new equivalent) to work cross plat. – Philip Pittle Mar 18 '22 at 17:46
  • hi @PhilipPittle i was able to fix the issue. I've Downgraded the version of system.drawing.common package from 6.0.0 to 4.7.0 and now is working . – sachin mathew Mar 19 '22 at 18:03

2 Answers2

1

You don't need to downgrade the package from v6.0.0. In .NET 6 you can fix the issue by adding this line to your startup code (before calling any GDI-dependent code):

AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);

But please note that this will not work in v7.0.0 and above. Unix support has already been removed from the 7.0.0-preview.* versions.

György Kőszeg
  • 17,093
  • 6
  • 37
  • 65
0

The issue was with the version of System.Drawing.Common package I am using. I've downgraded the package from 6.0.0 to 4.7.0 and the error went away.

sachin mathew
  • 1,432
  • 11
  • 19