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
If a struct contains a static field that is of the same type as itself and also nullable then referencing the type during runtime will result in a TypeLoadException with no explanation to why it fails to load the type.
Reproduction Steps
Program.cs
System.Console.WriteLine(typeof(TestStruct1));
TestStruct1.cs
public struct TestStruct1
{
public static TestStruct1? Instance;
}
Remarking the field TestStruct1.Instance results in the expected behavior which is that the name of the struct "TestStruct1" is rendered to console. Removing the Nullable-part or changing to another struct (as Nullable) of the field type works as intended.
Actual behavior
TypeLoadException when the type is referenced in runtime. Changing from typeof(TestStruct1) to new TestStruct1() in Program.cs makes no difference.
Regression?
No response
Known Workarounds
Write code that does not use this pattern at all; struct with static nullable field of itself.
Configuration
Tested with:
.NET 6 and 7
Windows 10 and 11
Visual Studio 2022 17.4.3 and 14.7.0
Intel x64 CPU
Published Release build and debug
Other information
No response
The text was updated successfully, but these errors were encountered:
Description
If a struct contains a static field that is of the same type as itself and also nullable then referencing the type during runtime will result in a TypeLoadException with no explanation to why it fails to load the type.
Reproduction Steps
Program.cs
TestStruct1.cs
ConsoleApp1.csproj
Expected behavior
Remarking the field TestStruct1.Instance results in the expected behavior which is that the name of the struct "TestStruct1" is rendered to console. Removing the Nullable-part or changing to another struct (as Nullable) of the field type works as intended.
Actual behavior
TypeLoadException when the type is referenced in runtime. Changing from
typeof(TestStruct1)
tonew TestStruct1()
in Program.cs makes no difference.Regression?
No response
Known Workarounds
Write code that does not use this pattern at all; struct with static nullable field of itself.
Configuration
Tested with:
Other information
No response
The text was updated successfully, but these errors were encountered: