C#C
C#10mo ago
Nolram

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:
Process terminated. Failed to create generic virtual method implementation

Declaring type: MemoryPack.Formatters.MemoryPackableFormatter`1<GameCore.Scenes.Scene>
Method name: Serialize
Instantiation:
  Argument 00000000: MemoryPack.Internal.ReusableLinkedArrayBufferWriter

   at System.RuntimeExceptionHelpers.FailFast(String, Exception, String, RhFailFastReason, IntPtr, IntPtr) + 0x249
   at Internal.Runtime.TypeLoader.TypeLoaderEnvironment.ResolveGenericVirtualMethodTarget(RuntimeTypeHandle, RuntimeMethodHandle) + 0x256
   at System.Runtime.TypeLoaderExports.<>c.<GVMLookupForSlotSlow>b__8_0(IntPtr, IntPtr, Object, IntPtr&) + 0x3e
   at System.Runtime.TypeLoaderExports.CacheMiss(IntPtr, IntPtr, RuntimeObjectFactory, Object) + 0x3c
   at System.Runtime.TypeLoaderExports.GVMLookupForSlotSlow(Object, RuntimeMethodHandle) + 0x68
   at System.Runtime.TypeLoaderExports.GVMLookupForSlot(Object, RuntimeMethodHandle) + 0x91
   at MemoryPack.MemoryPackWriter`1.WriteValue[T](T&) + 0x3d
   at MemoryPack.MemoryPackSerializer.Serialize[T](T&, MemoryPackSerializerOptions) + 0x342
   at Game.Main(String[] args) + 0xaa


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!
Program.cs1.62KB
Was this page helpful?