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
Static fields should not contribute to cyclic struct layout #5479
This code will compile with C# 6.0 and is legal according to the CLI spec. The type definition is recursive but the layout of the struct is not because the field involved here is static. The CLR is unable to handle this though and fails at runtime with a TypeLoadException:
Unhandled Exception: System.TypeLoadException: Could not load type 'ConsoleApplication1.Program+MyStruct' from assembly 'ConsoleApplication59, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
This is known implementation limitation in CoreCLR - both the instance and static field layout is done together that results into this error. It is not easy to fix.
Static is one case, but another is the case of unreferenced generic type parameters. As pointed out elsewhere by Eric Lippert, the following code compiles, but throws a TypeLoadException when run:
structN<T>{}structM{publicN<M>E;}
Is this a result of the same "known implementation limitation"?
Activity
jkotas commentedon Apr 1, 2016
This is known implementation limitation in CoreCLR - both the instance and static field layout is done together that results into this error. It is not easy to fix.
BBI-YggyKing commentedon Oct 20, 2016
Static is one case, but another is the case of unreferenced generic type parameters. As pointed out elsewhere by Eric Lippert, the following code compiles, but throws a TypeLoadException when run:
Is this a result of the same "known implementation limitation"?
mangod9 commentedon Sep 16, 2020
Closing since there doesnt seem to be any particular reasons to be fix in the near term.