Type.GetType("namespace.a.b.ClassName") returns null
This code:
Type.GetType("namespace.a.b.ClassName")
returns null
.
and I have in the usings:
using namespace.a.b;
Update:
The type exists, it's in a different class library, and i need to get it by string name.
Solution 1:
Type.GetType("namespace.qualified.TypeName")
only works when the type is found in either mscorlib.dll or the currently executing assembly.
If neither of those things are true, you'll need an assembly-qualified name:
Type.GetType("namespace.qualified.TypeName, Assembly.Name")
Solution 2:
You can also get the type without assembly qualified name but with the dll name also, for example:
Type myClassType = Type.GetType("TypeName,DllName");
I had the same situation and it worked for me. I needed an object of type "DataModel.QueueObject" and had a reference to "DataModel" so I got the type as follows:
Type type = Type.GetType("DataModel.QueueObject,DataModel");
The second string after the comma is the reference name (dll name).