1

Closed

TypeLoadException for struct with static nullable field

description

Source:
struct MyStruct {
    public static MyStruct? Value;
}
This will throw a TypeLoadException at runtime.
Removing the ? makes it work fine.

Note that the old compiler incorrectly refused to compile this at all.
(since the field is static, this isn't actually a cycle)
Closed Aug 6, 2014 at 7:11 AM by TomasMatousek

comments

TomasMatousek wrote Aug 6, 2014 at 7:10 AM

This is a know limitation of the CLR type loader. The compiler compiles the code without reporting an error since it's correct according to the C# specification and it actually works on some CLI implementations.