kswoll / someta

General purpose meta programming with Fody
11 stars 3 forks source link

TypeLoadException when using class level type constraints #17

Open mmintoff opened 2 years ago

mmintoff commented 2 years ago
    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.

kswoll commented 2 years ago

Hey, sorry, didn't see this issue come in. I'll take a look.

mmintoff commented 2 years ago

Would greatly appreciate it. Tried to figure out what was wrong, but I'm very green when it comes to Mono.Cecil :)