You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NativeAOT runtime crash with source-generated serialization ('Failed to create generic virtual method implementation') #113664
While attempting to serialize a class containing a custom generic container containing an array of classes through a shared interface using the MemoryPack library for source-generated binary serialization, I have been running into a runtime crash I suspect may be a possible compiler bug:
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 have attached an example for reproduction. (It is only a single source file, but due to GitHub limitations I've had to place it into a ZIP container). Repro.zip
Activity
dotnet-policy-service commentedon Mar 18, 2025
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.
Fix dynamic static generic virtual method dispatch on generic types
Nolram12345 commentedon Mar 19, 2025
When can we expect this change to be available in the SDK?
Fix dynamic static generic virtual method dispatch on generic types (d…
MichalStrehovsky commentedon Mar 19, 2025
It will be in .NET 10 SDK nightly builds in a couple days: https://github.com/dotnet/sdk?tab=readme-ov-file#installing-the-sdk, make sure the project targets .NET 10 when using the SDK.
Nolram12345 commentedon Mar 19, 2025
I see, so I'll need to wait for .NET 10 to be released to be able to have this fix in production?
MichalStrehovsky commentedon Mar 19, 2025
Yes. We don't backport all fixes and this being broken on .NET 7/8/9 weakens the backporting argument significantly.