.NET 10 Rejects Dual-Size InlineArray Types, Triggering TypeLoadException at Runtime
A compatibility change in .NET 10 causes a TypeLoadException when the runtime loads a value type that combines InlineArrayAttribute with StructLayoutAttribute.Size, even if the code compiled without errors. The failure can appear late — triggered by reflection, interop, or serialization — rather than at compile time, making it easy to miss during initial testing. This happens because the two attributes create competing, ambiguous descriptions of the type's memory layout, which .NET 10 now explicitly rejects. Earlier runtimes permitted this combination through implementation-specific behavior, but Microsoft has documented the stricter enforcement as a binary compatibility change in .NET 10. The recommended fix is not to blindly remove the explicit size, but to understand its original interop intent and migrate the layout definition to an unambiguous wrapper struct.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in