Why System.Type.GetType fails on Enum types?

G

Guest

The following code

Type t = Type.GetType("System.Drawing.RotateFlipType", True);

always throws an exception:

An unhandled exception of type 'System.TypeLoadException' occurred in
WindowsApplication1.exe

Additional information: Could not load type System.Drawing.RotateFlipType
from assembly WindowsApplication1, Version=1.0.1693.20837, Culture=neutral,
PublicKeyToken=null.
 
I

Imran Koradia

Well, its not got to do with enum types since I could get the Type for enums
like say System.Reflection.BindingFlags and others. I could also get the
type by doing:

Dim eFlipType as System.Drawing.RotateFlipType
Dim t as Type = eFlipType.GetType()

which worked fine. I couldn't get the the case you mentioned to work. In
fact, try getting the type for any of the objects in the System.Drawing
namespace (or any namespace within System.Drawing) using
Type.GetType(String) or any of its versions and you'll blow up (well,
atleast I did). This is most likely a bug since its working for all other
types in other namespaces. I could very well be wrong though. You might want
to verify if this is also happening in your case.

Imran.
 
M

Mattias Sjögren

Imran,
This is most likely a bug since its working for all other
types in other namespaces.

No it isn't. The docs for Type.GetType clearly states that you must
supply the assembly name where the type is implemented, unless it's in
Mscorlib.dll or the calling assembly. This should work:

Type.GetType("System.Drawing.RotateFlipType, System.Drawing,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")



Mattias
 
I

Imran Koradia

Oops..you're right. thanks for pointing that out.
As I also mentioned, I could very well be wrong :)
 

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