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:
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:
"Namespace.TypeName, AssemblyName"
assembly.GetType(string)
, where assembly
is the correct assemblyAppDomain
, checking each in turnCheck this Jon Skeet answer on this : https://stackoverflow.com/a/3758295/314488
using System;
using System.Windows.Forms;
class Test
{
static void Main()
{
string name = typeof(Form).AssemblyQualifiedName;
Console.WriteLine(name);
Type type = Type.GetType(name);
Console.WriteLine(type);
}
}
Output:
System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
System.Windows.Forms.Form
Note that if you're using a strongly named assembly (like Form in this case) you must include all the assembly information - versioning, public key token etc.
You need to use assembly-qualified name of the type
Type tForm = Type.GetType("System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");