简体   繁体   English

在运行时加载Assemby

[英]load assemby at runtime

I load my assembly at runtime (but this assemby is not refenced by the project) 我在运行时加载程序集(但该Assemby未被项目引用)

Assembly a = Assembly.LoadFile(@"fulpath\assName.dll");

after that I want to use one class from this dll by reflection 之后,我想通过反射从此dll使用一个类

obj = Activator.CreateInstance(Type.GetType("assemblyqualifiedname"));
mi = obj.GetType().GetMethod("methodname");
mi.Invoke(obj, null);

unfortunately , bull returns from Type.GetType("assemblyqualifiedname"); 不幸的是,公牛从Type.GetType("assemblyqualifiedname");返回Type.GetType("assemblyqualifiedname");

I dont understand , why I must to add reference od dll to project ? 我不明白,为什么我必须在项目中添加引用od dll?

Load assembly should be enough , but it doesnt . 负载组装应该足够,但事实并非如此。

thanks ... 谢谢 ...

When you load an assembly manually, you should use its getType method. 手动加载程序集时,应使用其getType方法。 Type.getType will use the calling assembly and its reference to search for the type. Type.getType将使用调用程序集及其引用来搜索类型。 a.GetType will find the type, because it looks inside the loaded assembly. a.GetType将查找类型,因为它在已加载的程序集中内部。

您反对在项目中添加对DLL的引用是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM