I’ve been working with some code that I needed to add a module too and I thought I had everything set up correctly but this last bit has got me stumped.
It seems relatively simple, I’m passing in a type to a Generic Method
var name typeof(T).AssemblyQualifiedName;
So that I can then do this
var type = Type.GetType(name);
however it’s throwing an exception at that last line with name being null
I’ve been reading around type reflection I know that GetType expects the fully qualified assembly name but I don’t understand why it’s coming back as null.
Does it mean I’m doing something fundamentally wrong with my code as i assumed that AssemblyQualifiedName is emitted from a type as it knows how it’s been referenced?
Well
AssemblyQualifiedNamecan return null:It doesn’t look like it should actually represent a generic type parameter if you’re really just using
typeof(T)– unless the generic method is being called via reflection in some bizarre way.Why are you trying to use
Type.GetTypethough? It sounds like all you need is… wouldn’t that do exactly what you want? Why go via the name of the type?