runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Exception System.TypeLoadException in case of recursive generic parameter

Open 3fbaea00 opened this issue 2 years ago • 4 comments

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

3fbaea00 avatar Nov 01 '24 15:11 3fbaea00

Possible duplicate of #104511

colejohnson66 avatar Nov 01 '24 16:11 colejohnson66

I have the same issue when i want to use MEDI on Apple platforms. I am using dotnet 9.

M0n7y5 avatar Jul 16 '25 15:07 M0n7y5

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

3fbaea00 avatar Jul 17 '25 13:07 3fbaea00

Closing in favor of https://github.com/dotnet/runtime/issues/130068.

MichalStrehovsky avatar Jul 01 '26 06:07 MichalStrehovsky