How to get a type from an unreferenced assembly?

Don*_*sic 3 .net c# reflection assemblies

GetType() returns null when the type exists in an unreferenced assembly. For example, when the following is called "localType" is always null (even when using the full namespace name of the class):

Type localType = Type.GetType("NamespaceX.ProjectX.ClassX");
Run Code Online (Sandbox Code Playgroud)

I don't see any reason why Type.GetType shouldn't be able to retrieve a type from an unreferenced assembly, so

How can the type of an unreferenced assembly be retrieved?

Ant*_*ean 7

用于LoadFrom从其位置加载未引用的程序集.然后打电话GetType.

Assembly assembly = Assembly.LoadFrom("c:\ProjectX\bin\release\ProjectX.dll");
Type type = assembly.GetType("NamespaceX.ProjectX.ClassX");
Run Code Online (Sandbox Code Playgroud)

如果要加载的程序集位于要加载的程序集的私有路径中(如"c:\ ProjectY\bin\release\ProjectX.dll"),则可以使用Load.

Assembly assembly = Assembly.Load("ProjectX.dll");
Type type = assembly.GetType("NamespaceX.ProjectX.ClassX");
Run Code Online (Sandbox Code Playgroud)