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.
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.
If it's a nested Type, you might be forgetting to transform a . to a +
Regardless,
typeof( T).FullName
will tell you what you should be sayingEDIT: BTW the usings (as I'm sure you know) are only directives to the compiler at compile time and cannot thus have any impact on the API call's success. (If you had project or assembly references, that could potentially have had influence - hence the information isnt useless, it just takes some filtering...)
I am opening user controls depending on what user controls the user have access to specified in a database. So I used this method to get the TypeName...
So now one can use the value returned in strType to create an instance of that object.
As Type.GetType(String) need the Type.AssemblyQualifiedName you should use Assembly.CreateQualifiedName(String, String).
As assemblyName you don't need to FullName, only the name without the Version, Culture and PublicKeyToken is required.