Type.GetType(String)

P

Peter

Hi, the following is my question defined as below:
- C# language
- a custom dll,the class name = theNS.theClass
- in a testing project, after add the reference
- code: Type theType = Type.GetType("theNS.theClass");
- problem : theType is set to null.
Please advice. Thanks.
Peter
 
M

Mattias Sjögren

Peter,
Hi, the following is my question defined as below:
- C# language
- a custom dll,the class name = theNS.theClass
- in a testing project, after add the reference
- code: Type theType = Type.GetType("theNS.theClass");
- problem : theType is set to null.

Type.GetType only search Mscorlib.dll and the calling assembly when
you specify only a type name. The solution is to specify the full type
and assembly name, such as

Type.GetType("theNS.theClass, YourAssembly");

But if you have a reference to that assembly, it's even better to use
the typeof operator.

typeof(theNS.theClass),



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top