Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Dec 08, 2021 4:47 pm

When creating a Workbook with
Code: Select all
var workbook = new Workbook();

in a.Net Core 5 apllication running in a Linux docker container I get an "System.PlatformNotSupportedException" for System.Drawing.Common.
Does Spire.XLS need a special lib installed as does Spire.Doc on Linux?

Exception 01 ===================================
Type: System.TypeInitializationException
Source: sprឳ, Spire.XLS, Version=9.2.16.19320, Culture=neutral, PublicKeyToken=663f351905198cb3
Message: The type initializer for 'sprឳ' threw an exception.
Trace: at sprឳ..ctor()
at sprᝫ..ctor()
at sprង..ctor()
at Spire.Xls.Workbook..ctor()
at ... /Actions/Eventbus/Document/CreateDocumentCommandV2.cs:line 267
at ... /Actions/Eventbus/Document/CreateDocumentCommandV2.cs:line 688
Location:
Method: Void .ctor() (0, 0)
Exception 02 inner --------------------------
Type: System.TypeInitializationException
Source: System.Drawing.SafeNativeMethods+Gdip, System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Message: The type initializer for 'Gdip' threw an exception.
Trace: at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, IntPtr scan0, IntPtr& bitmap)
at Spire.Xls.Core.Spreadsheet.UtilityMethods.ᜀ(Int32 A_0, Int32 A_1, PixelFormat A_2)
at Spire.Xls.Core.Spreadsheet.UtilityMethods.ᜀ(Int32 A_0, Int32 A_1)
at sprឳ..cctor()
Location:
Method: Int32 GdipCreateBitmapFromScan0(Int32, Int32, Int32, Int32, IntPtr, IntPtr ByRef) (0, 0)
Exception 03 inner --------------------------
Type: System.PlatformNotSupportedException
Source: System.Drawing.LibraryResolver, System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Message: System.Drawing.Common is not supported on non-Windows platforms. See ...
Trace: at System.Drawing.LibraryResolver.EnsureRegistered()
at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
at System.Drawing.SafeNativeMethods.Gdip..cctor()
Location:
Method: Void EnsureRegistered() (0, 0)

gfischer
 
Posts: 7
Joined: Thu Nov 04, 2021 9:34 am

Thu Dec 09, 2021 10:56 am

Hello,

Thank you for your inquiry.
I did an initial test in the docker environment,but did not reproduce your problem. In response to the error message you provided, I suggest you install the "SkiaSharp.NativeAssets. Linux" plug-in through Nuget Manager. If the problem still exists after trying, please provide the following information for us to investigate. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.
1) Your test project.
2) Is your docker based on Ubuntu or CentOS?
3) Your dockfile.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Dec 10, 2021 8:44 am

Adding the NuGet didn't solve the problem, but following the instructions in https://docs.microsoft.com/en-us/dotnet ... ndows-only did. I'm a bit confused why that was necessary, because I'm running on Net 5 and not Net 6, but we have kinda mixed environment right now and maybe that interfered.

TLDR: add a runtimeconfig.template.json file to your project with that content
Code: Select all
{
  "configProperties": {
    "System.Drawing.EnableUnixSupport": true
  }
}

gfischer
 
Posts: 7
Joined: Thu Nov 04, 2021 9:34 am

Fri Dec 10, 2021 8:52 am

Hello,

Thank you for sharing the solution.
Glad to hear that the solution has been found by yourself.
If you encounter other issues related to our products in the future, please feel free to contact us. Wish you all the best!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS