Use ReadyToRun or Ahead-Of-Time (AOT) Compilation
.NET ReadyToRun (R2R) is a form of ahead-of-time (AOT) compilation.
Enabling ReadyToRun compilation during deployment might violate tampering protection and result in exceptions such as the following:
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronPdf, Version=2024.2.0.2, Culture=neutral, PublicKeyToken=94e1c31412563c75 assembly is not authentic. Please try to reinstall the nuget package
at IronPdf.PdfDocument.uswvws(Boolean vhfwdf)
at IronPdf.PdfDocument.get_BinaryData()
at IronPdf.PdfDocument.SaveAs(String FileName, Boolean SaveAsRevision)
at Program.<Main>(String[] args) in C:\csharppro\aottest\aottest\Program.cs:line 5
Reason
According to Microsoft documentation, the SDK will precompile the assemblies that are distributed with the application. For self-contained applications, this set of assemblies will include the framework. It's important to note that C++/CLI binaries are not eligible for ReadyToRun compilation.
Solution
To exclude specific assemblies from ReadyToRun processing, use the <PublishReadyToRunExclude>
list in your project file. For example, to exclude the IronPdf.dll
assembly:
<ItemGroup>
<!-- Excludes IronPdf.dll from ReadyToRun compilation -->
<PublishReadyToRunExclude Include="IronPdf.dll" />
</ItemGroup>
<ItemGroup>
<!-- Excludes IronPdf.dll from ReadyToRun compilation -->
<PublishReadyToRunExclude Include="IronPdf.dll" />
</ItemGroup>
This XML snippet should be added to your project file (.csproj
) to prevent the specified assemblies from being precompiled with ReadyToRun, thus avoiding potential licensing or tampering issues.