Failure to get generic type SortedList in Type.GetType()

D

djpenton

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.
 
M

Mattias Sjögren

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
 
M

Moty Michaely

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
 

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