Skip to content

[Mono] TypeLoadException for class with variant interfaces #68033

@martinpotter

Description

@martinpotter

Description

Due to the changes made in #57086, initializing a type with variant interfaces can result in a TypeLoadException. The exception only occurs when using the Mono version of the Microsoft.NETCore.App runtime.

Reproduction Steps

public abstract class Foo : IComparable<Foo>, IComparable<Bar>
{
	public abstract int CompareTo(Foo other);
	public abstract int CompareTo(Bar other);
}

public sealed class Bar : Foo
{
	public override int CompareTo(Foo other)
	{
		return 1;
	}

	public override int CompareTo(Bar other)
	{
		return 1;
	}
}

Test method:

new Bar();

Expected behavior

Program runs without exception.

Actual behavior

The program throws an exception:

Unhandled Exception:
System.TypeLoadException: Recursive type definition detected TypeLoadExceptionBug.Bar
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Recursive type definition detected TypeLoadExceptionBug.Bar

Regression?

Yes. This works as expected when using Mono for net5.0 and net472.

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions