-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Description
Description
In .NET 8 there is a bug regarding the handling of generic types, which produces a TypeLoadException
Reproduction Steps
ON .NET 8 Compile & run the following C# console application code code:
public interface IGeneric<T>
{
}
public class DualGeneric<T1, T2> where T1 : T2
{
}
public class Record : DualGeneric<Record, IRecord>, IRecord
{
}
public interface IRecord : IGeneric<Record>
{
}
public interface IRecord<T> : IGeneric<Record<T>>
{
}
public class Record<T> : DualGeneric<Record<T>, IRecord<T>>, IRecord<T>
{
}
internal class Program
{
private static void Main(string[] args)
{
var record = new Record<int>();
Console.WriteLine("Works");
}
}Expected behavior
Program prints Works message.
Actual behavior
Actual result: System.TypeLoadException: 'GenericArguments[0], 'Record1[T]', on 'DualGeneric2[T1,T2]' violates the constraint of type parameter 'T1'.'
Regression?
Code runs perfectly fine, when it's targeting .NET 7
Known Workarounds
Run the code on .NET 7
Configuration
- .NET 8
- Windows 10 22H2
- X64
- Shouldn't be specific to configuration
Other information
No response
En3Tho