How to get type from unreferenced assembly?

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

Type localType = Type.GetType("NamespaceX.ProjectX.ClassX");

I see no reason why Type.GetType will not be able to extract the type from unreferenced assembly, so

How can I get the type of unregistered assembly?

+3
source share
2 answers

Use LoadFromto download an unpublished assembly from it. Then call GetType.

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

, (, "c:\ProjectY\bin\release\ProjectX.dll" ), Load.

Assembly assembly = Assembly.Load("ProjectX.dll");
Type type = assembly.GetType("NamespaceX.ProjectX.ClassX");
+7

MSDN

, ReflectionPermission , null.

, null , .

, GetType . , , , .

+1

All Articles