Problem Statement:
There is a DLL called CommonAssembly. This contains a namespace called CommonNamespace. This namespace contains a class called CommonClass.
Another project adds a reference to CommonAssembly and wants to get the type of CommonClass using the method Type.GetType.
Additional Information:
// This statement won’t work.
Type.GetType(“CommonClass”);
// This will not work either
Type.GetType(“CommonNamespace.CommonClass”);
Since CommonClass type is defined in a referred assembly, Type.GetType will not be able to get the required type.
Solution:
Type.GetType(“CommonNamespace.CommonClass, CommonAssembly”);
Anything that is given after the comma (“,”) is taken as the assembly name. This assembly is searched for the given type name.
If the required class is not encapsulated in any namespace, then omit the namespace name.
Type.GetType(“CommonClass, CommonAssembly”);
If this doesn’t work, then try giving the fully qualified name of the assembly.
You just saved my day!
It doesnt work..
Make sure you have given the correct qualified name. It should work.
Type.GetType(”CommonClass”, CommonAssembly);
should be
Type.GetType(”CommonClass, CommonAssembly”);
It’s right in the explaination….
“Anything that is given after the comma (”,”) is taken as the assembly name.”
Just not the example….
Oops, thanks for pointing it out, EzElmo.
You can use:
myObject.GetType().AssemblyQualifiedName
to get the right string name to put in to Type.GetType()
Parabéns pelo Post!
Salvou minha noite…
Obrigado!
Thanks.
I Saved my Job.
I Love You.
Thanks you very much!
you saved my life… I love U
Thanks. It works fine in my visual studio 2008.
And if the xxx.dll assembly isn’t on root workspace? this works fine only if the xxx.dll is in the same directory of the executable..
thanks. Its helped me too.
thanx worked perfectly! 5 stars.
Great !! I was facing this issue since last two days.
helped me, thanks alot
Just face palmed myself! Pretty obvious looking at it NOW 🙂
Cheers
Fantastic, thanks for this!!
[…] how do you request a Type check against the calling Assembly? I found this: https://generally.wordpress.com/2007/06/01/typegettype-and-referred-assemblies/. Which accurately describes how to dictate the Assembly to search for the […]
I like the helpful info you provide in your posts. I will bookmark your blog and check again here frequently. I’m quite sure I’ll learn many new stuff right here! Good luck for the next!
[…] how do you request a Type check against the calling Assembly? I found this: https://generally.wordpress.com/2007/06/01/typegettype-and-referred-assemblies/. Which accurately describes how to dictate the Assembly to search for the […]