public class Tester<T>
where T : class, new()
{
[MyAttribute]
public void Test()
{
Console.WriteLine("abc");
}
}
Calling
var t = new Tester<SomeClass>();
t.Test();
Gives the exception:
System.TypeLoadException: 'GenericArguments[0], 'T', on 'Tester.Tester`1[T]' violates the constraint of type parameter 'T'.'
Issue only happens with class/new() constraints and only at class level.
Method level constraints of this nature work fine.
Interface constraints at class level work fine.
Calling
Gives the exception:
System.TypeLoadException: 'GenericArguments[0], 'T', on 'Tester.Tester`1[T]' violates the constraint of type parameter 'T'.'
Issue only happens with class/new() constraints and only at class level. Method level constraints of this nature work fine. Interface constraints at class level work fine.