Domanda

The following code result in different results:

class X<R>
{
    public class Y { }
}

...

var t = typeof(X<int>.Y);
var n = t.ToString().Dump(); // <- X`1+Y[System.Int32]

Type.GetType(n).Dump(); // <-- X`1+Y[System.Int32]
t.Assembly.GetType(n).Dump(); // <-- null

Why Type.GetType(n) finds the type but t.Assembly.GetType(n) not?

È stato utile?

Soluzione

According to http://msdn.microsoft.com/en-us/library/y0cd10tb%28v=vs.110%29.aspx, Assembly.GetType(string) needs the FULL name of the type.

Try using FullName instead of ToString() on the type to get the full name, instead of the short name.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top