PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Nov 09, 2024 1:59 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: .NET 8 AOT support
PostPosted: Tue Dec 26, 2023 12:44 pm 
Offline

Joined: Tue Dec 26, 2023 12:32 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
 Post subject: Re: .NET 8 AOT support
PostPosted: Sun Dec 31, 2023 4:16 pm 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1007
Location: CCAA
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 too 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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
 Post subject: Re: .NET 8 AOT support
PostPosted: Tue Jan 02, 2024 7:10 am 
Offline

Joined: Tue Dec 26, 2023 12:32 pm
Posts: 2
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 too 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!


Top
 Profile  
Reply with quote  
 Post subject: Re: .NET 8 AOT support
PostPosted: Tue Aug 20, 2024 8:11 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3111
Location: Cologne, Germany
Setting `<TrimMode>partial</TrimMode>` worked for me.
But using `<TrimmerRootAssembly Include="PdfSharp" />` instead also worked for me and the resulting .EXE was much smaller.


Code:
    <PropertyGroup>
      <OutputType>Exe</OutputType>
      <TargetFramework>net8.0</TargetFramework>
      <ImplicitUsings>enable</ImplicitUsings>
      <Nullable>enable</Nullable>
      <PublishAot>true</PublishAot>
      <PublishTrimmed>true</PublishTrimmed>
      <!--<TrimMode>partial</TrimMode>-->
      <InvariantGlobalization>true</InvariantGlobalization>
    </PropertyGroup>
   
    <ItemGroup>
      <TrimmerRootAssembly Include="PdfSharp" />
    </ItemGroup>

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 41 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group