468,256 Members | 1,426 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,256 developers. It's quick & easy.

GetType fails for StringCollection

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.
Jul 21 '05 #1
3 1375
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2
> 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
Jul 21 '05 #3
Jonathan,
It would help me greatly if you could elaborate on using __typeof.
__typeof is a MC++ operator that returns the System::Type for a given
type known at compile time. It's documented here

http://msdn.microsoft.com/library/en...rf__typeof.asp

Are there any advantages to using one over the other?


__typeof gives you compile time checking. Type::GetType on the other
hand is more dynamic.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by AlexS | last post: by
4 posts views Thread by audipen | last post: by
2 posts views Thread by Dennis Myrén | last post: by
2 posts views Thread by Dan | last post: by
1 post views Thread by Juan Francisco Figueroa Perez | last post: by
8 posts views Thread by Naz | last post: by
3 posts views Thread by Jonathan | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.