Hi,
As I read the source code of rotor, I found the
Type.GetTypeHandle(object o)
always return a pointer to the MethodTable.
This could be a bug of the FCL and CLR (The same bug happens on the REAL
.NET Framework), since the Type.TypeHandle property works in a different
way: for normal Reference type, the TypeHandle is still the MethodTable
pointer. But for a type which has shared MethodTable (Ref Array, for
example), it would be pointer to a much complicated structure
(TypeDesc).
That makes a inconsistent.

Following sample demonstrates this problem:
...
//a bad situation! because TypeHandle is the internal identity of a
Type!
//how can string[] and type[] have the same TypeHandle?
Type[] ta = new Type[10];
string[] ts = new string[10];
Console.WriteLine(Type.GetTypeHandle(ta).Value ==
Type.GetTypeHandle(ts).Value); //prints True!

//even worse, We can't create a type from this invalid TypeHandle!
RuntimeTypeHandle rth = Type.GetTypeHandle(ta);
Type t = Type.GetTypeFromHandle(rth);            //here will throw an
exception!

//and, the RuntimeTypeHandle from Type.GetTypeHandle and Type.TypeHandle
is
not the same!
Type t1 = ta.GetType();
Console.WriteLine(t1.TypeHandle.Value == Type.GetTypeHandle(ta).Value);
//prints False!
...

Fortunately, this function is NEVER called in the whole FCL.
But, a bug is a bug. If anyone use GetTypeHandle, something whired would
happen.

Best Regards
Ming Chen

Reply via email to