GetType not working on custom assemblies in .NET 2.0

G

Guest

We have just migrated to VS 2005 and .NET 2.0, and are having some problems
wth GetType and a custom class whose assembly resides in the GAC.

In 1.1, we could call, for example:
System.Type.GetType(""ElanHomeProject.ElanControl.ElanKeyPad.Z100,
ElanHomeProject");

This work work just fine, returning the type of that particular class.

Now, in 2.0, that call results in a null Type, and the call only seems to
work if we make the GetType call as so:

System.Type.GetType(""ElanHomeProject.ElanControl.ElanKeyPad.Z100,
ElanHomeProject, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=f50445a37b571e16");

Additionally, a call such as:
Type objType = typeof(ElanHomeProject.ElanControl.ElanKeyPad.Z100);

works in 2.0, but the way our application is built, the type is passed as a
string, so we HAVE to use GetType.

Has anyone else had this problem? Can anyone suggest a solution where we
won't have to pass the Version, Culture and PublicKeyToken?

Thank you in advance!

Gabe
 
D

David Browne

Gabe Covert said:
We have just migrated to VS 2005 and .NET 2.0, and are having some
problems
wth GetType and a custom class whose assembly resides in the GAC.

In 1.1, we could call, for example:
System.Type.GetType(""ElanHomeProject.ElanControl.ElanKeyPad.Z100,
ElanHomeProject");

This work work just fine, returning the type of that particular class.

Now, in 2.0, that call results in a null Type, and the call only seems to
work if we make the GetType call as so:

System.Type.GetType(""ElanHomeProject.ElanControl.ElanKeyPad.Z100,
ElanHomeProject, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=f50445a37b571e16");

Additionally, a call such as:
Type objType = typeof(ElanHomeProject.ElanControl.ElanKeyPad.Z100);

works in 2.0, but the way our application is built, the type is passed as
a
string, so we HAVE to use GetType.

Has anyone else had this problem? Can anyone suggest a solution where we
won't have to pass the Version, Culture and PublicKeyToken?

Thank you in advance!


You can always just examine the loaded assemblies and grab the first type
with a matching name.

EG

static Type GetType(string name)
{
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
Type t = a.GetType(name);
if ( t != null)
return t;
}
return null;
}

David
 

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