PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

.NET 8 AOT support
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4525
Page 1 of 1

Author:  toraxe [ Tue Dec 26, 2023 12:44 pm ]
Post subject:  .NET 8 AOT support

Is it a hard task to get the PDFSharp to work with .NET 8 ahead-of-time (AOT) compiled to native code?

It would be nice to generate PDFs with C# with a high performant self containd application.

I have tried set the project property group <PublishAot>true</PublishAot>
and publish an console application.
It builds and publishes the files for win64 in my case with some trim warnings.
When i creates a new PDFDocument in the code and it throwes the exception:

Unhandled Exception: System.NotImplementedException: Cannot create value for key: /Info
at PdfSharp.Pdf.PdfDictionary.DictionaryElements.GetValue(String, VCF) + 0x34d
at PdfSharp.Pdf.Advanced.PdfTrailer.get_Info() + 0x20
at PdfSharp.Pdf.PdfDocument.get_Info() + 0x20
at PdfSharp.Pdf.PdfDocument..ctor(Stream) + 0x64

Author:  () => true [ Wed Dec 27, 2023 1:32 pm ]
Post subject:  Re: .NET 8 AOT support

Moved the topic.


Cannot reproduce.
See also: http://forum.pdfsharp.net/viewtopic.php?f=2&t=832

Author:  TH-Soft [ Sun Dec 31, 2023 4:16 pm ]
Post subject:  Re: .NET 8 AOT support

toraxe wrote:
Is it a hard task to get the PDFSharp to work with .NET 8 ahead-of-time (AOT) compiled to native code?
I dunno. Didn't try yet.

I think PDFsharp/MigraDoc use reflection to some extent. Creating a size-optimized self-contained package will not work as .NET removes to much code in the process.
Maybe the same problem occurs with AOT. Try a variant that does not remove heuristically unused code if there is one.

Author:  toraxe [ Tue Jan 02, 2024 7:10 am ]
Post subject:  Re: .NET 8 AOT support

TH-Soft wrote:
toraxe wrote:
Is it a hard task to get the PDFSharp to work with .NET 8 ahead-of-time (AOT) compiled to native code?
I dunno. Didn't try yet.

I think PDFsharp/MigraDoc use reflection to some extent. Creating a size-optimized self-contained package will not work as .NET removes to much code in the process.
Maybe the same problem occurs with AOT. Try a variant that does not remove heuristically unused code if there is one.


Thank you TH-Soft for your reply, I got it working by setting the property <TrimMode>partial</TrimMode>.
As you saied it dident remove as much code but it works.

Thanks!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/