Hi All,

Seems to be a specific failure with SortedList in getting type from
name. Is this a problem with the .NET framework?

When I run this line in the immediate window:
Type.GetType(typeof(SortedList<double,double>).ToString(),true)

I get
Could not load type 'System.Collections.Generic.SortedList`2' from
assembly 'mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.

These work:
Type.GetType(typeof(List<double>).ToString(),true)
Type.GetType(typeof(List<double>).FullName,true)
Type.GetType(typeof(double).ToString(),true)
Type.GetType(typeof(double).FullName.true)
typeof(SortedList<double,double>).FullName
typeof(SortedList<double,double>).ToString()

These fail:
Type.GetType(typeof(SortedList<double,double>).FullName,true)
Type.GetType(typeof(SortedList<int,int>).FullName,true)
Type.GetType(typeof(SortedDictionary<double,double>).FullName,true)
Type.GetType(typeof(SortedDictionary<double,double>).ToString(),true)

I have run out of things to try and test for. Let me know if you have
any ideas.

Cheers,
Dave.

Re: Failure to get generic type SortedList in Type.GetType() by Mattias

Mattias
Fri Jun 08 00:27:32 CDT 2007

>Seems to be a specific failure with SortedList in getting type from
>name. Is this a problem with the .NET framework?

No. The difference is that SortedList<TKEy, TValue> and
SortedDictionary<TKey, TValue> are implemented in System.dll while
List<T> and Double are in mscorlib.dll. If you look at the docs for
Type.GetType you'll find that for type names that aren't assembly
qualified, it only looks in Mscorlib.dll and the calling assembly.


Mattias

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

Re: Failure to get generic type SortedList in Type.GetType() by Moty

Moty
Fri Jun 08 01:30:11 CDT 2007

On Jun 8, 8:07 am, djpen...@gmail.com wrote:
> Hi All,
>
> Seems to be a specific failure with SortedList in getting type from
> name. Is this a problem with the .NET framework?
>
> When I run this line in the immediate window:
> Type.GetType(typeof(SortedList<double,double>).ToString(),true)
>
> I get
> Could not load type 'System.Collections.Generic.SortedList`2' from
> assembly 'mscorlib, Version=2.0.0.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089'.
>
> These work:
> Type.GetType(typeof(List<double>).ToString(),true)
> Type.GetType(typeof(List<double>).FullName,true)
> Type.GetType(typeof(double).ToString(),true)
> Type.GetType(typeof(double).FullName.true)
> typeof(SortedList<double,double>).FullName
> typeof(SortedList<double,double>).ToString()
>
> These fail:
> Type.GetType(typeof(SortedList<double,double>).FullName,true)
> Type.GetType(typeof(SortedList<int,int>).FullName,true)
> Type.GetType(typeof(SortedDictionary<double,double>).FullName,true)
> Type.GetType(typeof(SortedDictionary<double,double>).ToString(),true)
>
> I have run out of things to try and test for. Let me know if you have
> any ideas.
>
> Cheers,
> Dave.

Dear Dave,

Use typeof(SortedList<double,double>).AssemblyQualifiedName instead of
ToString or FullName.

Hope this helps.
Cheers,
Moty


Re: Failure to get generic type SortedList in Type.GetType() by djpenton

djpenton
Tue Jun 12 19:52:20 CDT 2007

Thanks Mattias and Moty, quite a difficult one.