Type.GetType returns null

S

Suresh

Hi,

I have an C# CSEXE.exe (CSexe.cs) and a CSDll.dll
(CSdll.cs). exe is compiled with a reference to dll.
Calling for the class Type defined in CSDLL.dll using
Type.GetType( "myDLLnamespace.CSDll" ) returns null. I
made sure that the fully qualified class defined in the
dll is case-sensitive.

// CSEXE.exe
// CSexe.cs
namespace myEXEnamespace {
public class CSexe {

public static main()
{
//This returns null
Type csdllType = Type.GetType
( "myDLLnamespace.CSdll" );
}
}
}

namespace myDLLnamespace {
public class CSdll {

public CSdll(){}

public int myFunc(int a)
{
return a*a;
}
}
}

Can anyone tell why does the Type.GetType() returns null.
I have even checked the assemblies in the current domain
by using Thread.GetDomain().GetAssemblies(), I could find
the CSDll.dll loaded in the Default appdomain. Is it a
bug in C# or am I missing something.

Thanks
Suresh
 
J

Jon Skeet [C# MVP]

Suresh said:
I have an C# CSEXE.exe (CSexe.cs) and a CSDll.dll
(CSdll.cs). exe is compiled with a reference to dll.
Calling for the class Type defined in CSDLL.dll using
Type.GetType( "myDLLnamespace.CSDll" ) returns null. I
made sure that the fully qualified class defined in the
dll is case-sensitive.

The problem is that Type.GetType, when just given a class name and not
the assembly information, only looks in the current assembly and
mscorlib. You could either fully specify the name (including the
assembly name, version etc) or you could use Assembly.GetType, having
loaded the assembly.
 

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