Type.GetType(“namespace.a.b.ClassName”) returns null

前端 未结 16 1350
旧巷少年郎
旧巷少年郎 2020-11-22 02:58

This code:

Type.GetType(\"namespace.a.b.ClassName\")

returns null.

and I have in the usings:

using nam         


        
16条回答
  •  [愿得一人]
    2020-11-22 03:44

    Try using the full type name that includes the assembly info, for example:

    string typeName = @"MyCompany.MyApp.MyDomain.MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
    Type myClassType = Type.GetType(typeName);
    

    I had the same situation when I was using only the the namesspace.classname to get the type of a class in a different assembly and it would not work. Only worked when I included the assembly info in my type string as shown above.

提交回复
热议问题