GetType fails for StringCollection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I tried using Type::GetType on
S"System.Collections.Specialized.StringCollection", but it returned NULL.
The only way it worked was when I used the fully qualified name, including
the assembly name, version, and token information.

This seems like a bug to me, since StringCollection is part of system.dll,
and I thought types in this DLL were automatically located using GetType, but
perhaps I am mistaken.
It seems to me that requiring all this information as part of the GetType
call is just asking for your code to be non-portable.

Does anyone have any more information on this? Any help is appreciated.
 
This seems like a bug to me, since StringCollection is part of system.dll,
and I thought types in this DLL were automatically located using GetType, but
perhaps I am mistaken.

Yes you were. The documentation states pretty clearly that GetType
only looks in the calling assembly and in mscorlib.dll unless you
include the assembly name.

It seems to me that requiring all this information as part of the GetType
call is just asking for your code to be non-portable.

So why are you using Type::GetType instead of referencing System.dll
and using the __typeof keyword?



Mattias
 
So why are you using Type::GetType instead of referencing System.dll
and using the __typeof keyword?

I have been developing exclusively on Unix for 13 years. This is my first
foray into Windows, so I am a relative newbie.

It would help me greatly if you could elaborate on using __typeof. In my
case, I needed to create a DataColumn for a DataTable, so I had no object to
refer to when creating the column type. Are there any advantages to using
one over the other?

Thanks,
- Jon
 
Back
Top