Exception System.TypeLoadException in case of recursive generic parameter
Description
This code throws the System.TypeLoadException exception: “Could not load type ”{A or B in this case}" from assembly {Assembly}":
A a = new();
struct G<T>;
struct B
{
A A;
}
struct A
{
G<B> B;
}
This occurs in the line A a = new();, and it will also occur if replace it with B b = new();
Example of a real exception:
System.TypeLoadException: 'Could not load type 'A' from assembly 'ConsoleTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.'
Reproduction Steps
A a = new();
struct G<T>;
struct B
{
A A;
}
struct A
{
G<B> B;
}
Expected behavior
there should be no exception
Actual behavior
exception thrown
Regression?
No response
Known Workarounds
No response
Configuration
Net 8.0.400. CoreCLR 8.0.824.36612 Windows 11 24H2 x64
Other information
I have just discovered a similar problem occurring in C# 6: https://github.com/dotnet/runtime/issues/6924
Possible duplicate of #104511
I have the same issue when i want to use MEDI on Apple platforms. I am using dotnet 9.
I checked in .NET 9.0.0 and the error persisted. In .NET 10.0-preview6, the application crashed with the exception code: 0xe0434352 without any additional information
Closing in favor of https://github.com/dotnet/runtime/issues/130068.