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

前端 未结 16 1693
旧巷少年郎
旧巷少年郎 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:33

    You can also get the type without assembly qualified name but with the dll name also, for example:

    Type myClassType = Type.GetType("TypeName,DllName");
    

    I had the same situation and it worked for me. I needed an object of type "DataModel.QueueObject" and had a reference to "DataModel" so I got the type as follows:

    Type type = Type.GetType("DataModel.QueueObject,DataModel");
    

    The second string after the comma is the reference name (dll name).

提交回复
热议问题