Type.GetType returns null

  • Thread starter Thread starter Suresh
  • Start date Start date
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
 
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.
 
Back
Top