Support .NET 8 Native AOT deployment

Starting from .NET 7 a feature called .NET native ahead-of-time (AOT) has been introduced, and since .NET 8 support for Native AOT has been added to .NET Core.Publishing and deploying a native AOT app provides a lot of benefits, see: ASP.NET Core support for native AOT | Microsoft Learn

In an effort to migrate our codebase we tried to use Aspose.Cells in .NET 8 with native AOT deployment. Here is the test project: AsposeTestProjectNet8.zip (935 Bytes)

It contains the following test code:

// Instantiate a Workbook object that represents Excel file.
Workbook wb = new Workbook();

// When you create a new workbook, a default "Sheet1" is added to the workbook.
Worksheet sheet = wb.Worksheets[0];

// Access the "A1" cell in the sheet.
Cell cell = sheet.Cells["A1"];

// Input the "Hello World!" text into the "A1" cell
cell.PutValue("Hello World!");

// Save the Excel file.
wb.Save("MyBook_out.xlsx");

The application runs fine in Debug mode, a spreadsheet ‘MyBook_out.xlsx’ is generated.

But if we publish the application in Release mode, we get the following warnings:

C:\AsposeTestProjectNet8>dotnet publish
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  Restored C:\AsposeTestProjectNet8\AsposeTestProjectNet8.csproj (in 396 ms).
  AsposeTestProjectNet8 -> C:\AsposeTestProjectNet8\bin\Release\net8.0-windows\win-x64\AsposeTestProjectNet8.dll
  Generating native code
C:\Users\Administrator\.nuget\packages\aspose.cells\23.11.0\lib\net7.0-windows7.0\Aspose.Cells.dll : warning IL2104: Assembly 'Aspose.Cells' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\AsposeTestProjectNet8\AsposeTestProjectNet8.csproj]
ILC : warning IL3000: d.(Int32,,Boolean&,Boolean): 'System.Reflection.Assembly.Location.get' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling System.AppContext.BaseDirectory'. [C:\AsposeTestProjectNet8\AsposeTestProjectNet8.csproj]
C:\Users\Administrator\.nuget\packages\aspose.cells\23.11.0\lib\net7.0-windows7.0\Aspose.Cells.dll : warning IL3053: Assembly 'Aspose.Cells' produced AOT analysis warnings. [C:\AsposeTestProjectNet8\AsposeTestProjectNet8.csproj]
  <unknown>:0: error: symbol 'Aspose_Cells_____813___' is already defined
  AsposeTestProjectNet8 -> C:\AsposeTestProjectNet8\bin\Release\net8.0-windows\win-x64\publish\

The resulting application is not able to run:

C:\AsposeTestProjectNet8\bin\Release\net8.0-windows\win-x64\publish>AsposeTestProjectNet8.exe
Unhandled Exception: System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Reflection.Assembly.GetCallingAssembly() + 0x62
   at ♥♥↨►.☻(Int32, Boolean) + 0xd7
   at ♥♥↨►.☻(Int32) + 0x50
   at ☼♥↨►.♣↑↨►() + 0x75
   at ☼♥↨►.♠↑↨►(d) + 0x37
   at ☼♥↨►.c() + 0xa0
   at ♠▬↑↨.♠() + 0xb
   at ☼▬↑↨.☻(Int64, Boolean) + 0x1b
   at Aspose.Cells.Workbook..ctor(FileFormatType) + 0x7f
   at AsposeTestProjectNet8.Program.Main(String[] args) + 0x12e
   at AsposeTestProjectNet8!<BaseAddress>+0xdf8143

Is it possible that support for Native AOT will be added in the future for the Aspose.Cells .NET library? It will greatly improve the deployment of our .NET 8 applications.

More details and documentation about the limitations of Native AOT deployment can be found here: Native AOT deployment overview - .NET | Microsoft Learn

@perfectxl
Thank you for providing resources about using our component for Native AOT deployment. We will investigate it soon and give feedback when we get some findings.

@perfectxl
At present, we do not support .NET 8 Native AOT deployment.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-54764

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.