Aspose.Email 25.4.1 nuget - not working when .Net Native Tool Chain is enabled

Hi,

When I refer Aspose.Email nuget package in my UWP app, it works fine when I disable .Net Native Tool Chain. But when I enable, the expected functionalities of Aspose.Email nuget are throwing the below exceptions

When I invoke the method PersonalStorage.FromFile method to read a PST file, it throws the below exception

System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property. ---> System.TypeLoadException: Cannot load type 'System.Void, netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
   at a.fu(Int32, v, Boolean&, Boolean) + 0x31c
   at a.KE(Int32, Boolean) + 0x281
   at a.FE(Object[], Type[], Type[], Object[]) + 0x195
   at qUE.WUE(a) + 0x73
   at qUE.oUE() + 0xad
   at hUK..cctor() + 0x9
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xf1
 
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x1ad
   at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstruction(Void, StaticClassConstructionContext) + 0xf
   at Aspose.Email.Storage.Pst.PersonalStorage.u(Stream, PersonalStorageLoadOptions, CancellationToken) + 0x27
   at Aspose.Email.Storage.Pst.PersonalStorage.FromStream(Stream, Boolean) + 0x40
   at Aspose.Email.Storage.Pst.PersonalStorage.FromFile(String, Boolean) + 0xe5
   at AsposeNTC.MainPage.<ReadPST_Click>d__2.MoveNext() + 0x28b
System.TypeLoadException: Cannot load type 'System.Void, netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
   at a.fu(Int32, v, Boolean&, Boolean) + 0x31c
   at a.KE(Int32, Boolean) + 0x281
   at a.FE(Object[], Type[], Type[], Object[]) + 0x195
   at qUE.WUE(a) + 0x73
   at qUE.oUE() + 0xad
   at hUK..cctor() + 0x9
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xf1

When I invoke the method MailMessage.Load to read an EML file, it throws the below exception

System.TypeLoadException: Cannot load type 'System.IO.Stream, netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
   at a.fu(Int32, v, Boolean&, Boolean) + 0x31c
   at a.KE(Int32, Boolean) + 0x281
   at a.ME(Object[]) + 0xba
   at a.FE(Object[], Type[], Type[], Object[]) + 0x96
   at Aspose.Email.License.SetLicense(Stream) + 0x84
   at AsposeNTC.MainPage.<SetLicense_Click>d__1.MoveNext() + 0x2ba

Please let us know if the nuget is really compatible with .Net Native Tool Chain or if we have any other alternate solutions

Please find my POC app “AsposeNTC” in github
AsposeNTC.png (55.3 KB)

@Gokul_Ram

It appears you are encountering issues with the Aspose.Email NuGet package when the .NET Native Tool Chain is enabled in your UWP app. The exceptions you are seeing, such as System.TypeLoadException, typically indicate that certain types or assemblies are not being correctly resolved or included during the compilation process with the Native Tool Chain.

Cause: The issue likely stems from compatibility problems between the Aspose.Email package and the .NET Native Tool Chain, which can lead to certain types being stripped out during the build process.

Solution: Here are some steps you can take to troubleshoot and potentially resolve the issue:

  1. Check Compatibility: Ensure that the version of Aspose.Email you are using is compatible with UWP and the .NET Native Tool Chain. Specific versions may have known issues or limitations.

  2. Update Packages: Make sure you are using the latest version of the Aspose.Email NuGet package. Updates often include bug fixes and improvements that may resolve your issue.

  3. Review Project Settings: Double-check your project settings to ensure that all necessary assemblies are included in the build. Adjust the “Linking” settings in your UWP project to prevent the Native Tool Chain from stripping out required types.

  4. Use Reflection: If certain types are being stripped out, consider using reflection to access them dynamically. This can sometimes bypass issues with type loading.

  5. Test Without Native Tool Chain: Since you mentioned that everything works fine without the Native Tool Chain, isolate the problem further by testing with a minimal UWP app that only includes Aspose.Email to see if the issue persists.

  6. Consult Documentation: Review the Aspose.Email documentation for any specific notes regarding UWP and the .NET Native Tool Chain. There may be additional configuration steps or known issues documented.

Next Steps: If these steps do not resolve the issue, reach out to Aspose support with detailed information about your project setup and the exceptions you are encountering. They may provide more specific guidance or updates regarding compatibility.

Please let me know if you need further assistance!

As we are planning to upload our app in Microsoft Store, we will have to compile our app with .Net Native Tool Chain. So Disabling .Net Native Tool Chain option is ruled out for us.

We couldn’t find any documentation related to .Net Native Tool Chain in Aspose pages because of which we are not able to proceed further in checking the compatibility of the nuget package with UWP as well. Having no documentation on .Net Native Tool Chain leaves an open end, that the latest version could also have the issue. So upgrading to latest version of Aspose.Email nuget package might not help us.

PFB the target version & min version we have set in the POC app that we mentioned earlier

TargetPlatformVersion - 10.0.19041.0
TargetPlatformMinVersion - 10.0.18362.0

Please let me know if any further details required from my end

Hello @Gokul_Ram,

The issue occurs because the .NET Native Tool Chain aggressively optimizes assemblies when compiling UWP apps. It removes types and methods that are not directly referenced, which breaks libraries that rely on reflection, late binding, and dynamic code execution.

In your case, required types such as System.Void and System.IO.Stream from netstandard were trimmed away, leading to the runtime exceptions.

To fix this, you need to explicitly instruct the .NET Native compiler to keep these types and metadata by adding runtime directives in the Default.rd.xml file of your UWP project. For example:

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>

    <Namespace Name="System.IO" Dynamic="Required All" />

    <Namespace Name="System" Dynamic="Required All" />

    <Assembly Name="netstandard" Dynamic="Required All" />

    <Assembly Name="Aspose.Email" Dynamic="Required All" />
  </Application>
</Directives>

The directive Dynamic="Required All" ensures that metadata for all types in the specified assembly is preserved, making them available for reflection at runtime.

Add this rd.xml to your UWP project, ensure it is included in the build, and then rebuild with the .NET Native Tool Chain enabled.

Hi @margarita.samodurova

We actually tried multiple run time directives like those you have shared above & nothing helped us in fixing the issue. Also now we again tried the entries you have shared here in our POC we mentioned above by adding these entries in the Default.rd.xml of our UWP project. Still the issue persists. Could you please check further & help us on this.

@Gokul_Ram,

We will review the details and get back to you shortly.

@Gokul_Ram
We have opened the following investigation ticket in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): EMAILNET-41623

While you continue investigating the issue, could you please confirm whether the Aspose.Email NuGet package is compatible with .Net Native Tool Chain compilation? Since our application is primarily a UWP app that we intend to distribute via the Microsoft Store, enabling Native Tool Chain has become a necessity.

It would also be very helpful if you could share any references or examples of the library being successfully used in a UWP app with this enabled.

Thank you for your support.

Hello,

We are currently investigating the compatibility of the Aspose.Email with .NET Native Tool Chain compilation in UWP apps.
At this moment, we cannot confirm full support for this scenario.
Once our internal review is complete, we will provide you with an update.

Thank you.

Hi @margarita.samodurova

I see the status of this issue “EMAILNET-41623” being displayed as Resolved. Attaching the screenshot of the same for your reference. Does this mean, we have any update on this or the issue has been fixed?

Screenshot 2025-09-10 104654.png (49.6 KB)

Hello @Gokul_Ram,

We’re sorry for the delay in getting back to you.
The ticket has been resolved with the resolution Won’t Fix. Unfortunately, we cannot resolve this issue.

The cause lies in the third-party obfuscator we use to protect our product. Since it relies on code virtualization, this unfortunately makes it incompatible with .NET Native (required for UWP). Removing this layer of protection would compromise product security, so we’re unable to provide a fix.

Thank you for your understanding.