C#.NET - Type.GetType(“System.Windows.Forms.Form”) returns null

后端 未结 3 1754
Happy的楠姐
Happy的楠姐 2021-01-28 10:42

I have a snippet of code in my application (which references System.Windows.Forms) which attempts to resolve type information for a Form class like so:

3条回答
  •  滥情空心
    2021-01-28 11:05

    Type.GetType(string) checks a few different things: if the string passed includes assembly information, then it will look there. Otherwise, the calling assembly and a few other system assemblies are checked (probably System and mscorlib). It does not check every assembly.

    So, you have a few options:

    • include the assembly information in the string, i.e. "Namespace.TypeName, AssemblyName"
    • use assembly.GetType(string), where assembly is the correct assembly
    • manually loop over all the assemblies loaded in the current AppDomain, checking each in turn

提交回复
热议问题