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 your class is not in current assambly you must give qualifiedName and this code shows how to get qualifiedname of class
and then you can get type with qualifiedName
If the assembly is part of the build of an ASP.NET application, you can use the BuildManager class:
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.
try using this method
For me, a "+" was the key! This is my class(it is a nested one) :
and this line of code worked:
This solution above seems to be the best to me, but it didn't work for me, so I did it as follows:
The precondition is that you know the path of the assembly. In my case I know it because this is an assembly built from another internal project and its included in our project's bin folder.
In case it matters I am using Visual Studio 2013, my target .NET is 4.0. This is an ASP.NET project, so I am getting absolute path via
HttpContext
. However, absolute path is not a requirement as it seems from MSDN on AssemblyQualifiedNames