NativeAOT Serialization Troubles
I'm trying to serialize the following (in an ideally fast manner and binary format, but I am willing to compromise) using NativeAOT (this is a requirement!):
A class containing a custom SparseSet (2 arrays internally) implementation containing a set of classes deriving from a shared interface.
I'm currently using MemoryPack for this, however it is not working whatsoever, and the following error occurs:
I've attached a sample of this scenario reproducing the above error. It works fine when not using NativeAOT, but as I mentioned NAOT is a requirement for me.
If anyone has any ideas on how to get this to serialize at all - no matter using what library or whatever - please inform me!
9 Replies
Should be fixed in 8.0 tho
This issue is happening on .NET 9, so clearly something still seems wrong
I have read this and followed their documentation, but as I just mentioned, the issue still occurs. Other MemoryPack serialisations work; just not this stack of generic container & interface-derived class
Iirc we had some issues where ModuleInitializer was not called with NativeAOT for some reason and union types were not registered.
Had to manually register them. Like
Could also have been that none of the ModuleInitializers were called and as a result all types had to be registered manually. Don't have access to the project anymore and cannot check sorry
Thank you for your input - I have already tried this, and unfortunately this does not solve the issue. The issue does not seem to be that NAOT is stripping out serialisation logic, but rather that something in the NAOT runtime itself seems to fail.
Did you already try to configure the trimmer with a root descriptor file to tell it not to trim away specific assemblies/types/... ?
I believe I have - but I can try again, just in case.
(Git issue about this: https://github.com/dotnet/runtime/issues/113664)
Seems a PR regarding this issue has been created!
https://github.com/dotnet/runtime/pull/113684
GitHub
Fix dynamic static generic virtual method dispatch on generic types...
Fixes #113664.
When we resolve dispatch for a static generic virtual method dynamically (e.g. after MakeGenericType or another generic virtual method call) we run the runtime type loader logic to d...
... and merged!