Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeLoadException when using class level type constraints #17

Open
mmintoff opened this issue May 27, 2022 · 2 comments
Open

TypeLoadException when using class level type constraints #17

mmintoff opened this issue May 27, 2022 · 2 comments

Comments

@mmintoff
Copy link

    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
Copy link
Owner

kswoll commented Jun 30, 2022

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

@mmintoff
Copy link
Author

mmintoff commented Jul 4, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants