从C#代码加载动态托管DLL的代码 [英] code to load dynamically managed-DLL from C# code

查看:263
本文介绍了从C#代码加载动态托管DLL的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想动态加载dll。但是没有添加dll的引用,以避免我的C#应用​​程序只从特定的地方加载dll 。



因为以下原因 -

- 我正在安装一个软件&它会在它的安装文件夹中生成一些dll。

- 因此如果安装了同一软件的多个版本,那么将在各自的安装文件夹中生成此dll的多个版本。



- 所以我的要求是,如果有多个软件安装(如上所述),我的C#应用​​程序将决定dll需要加载的位置



所以一切都会在运行时发生。



很快就会引导我。



谢谢

Hi,
I want to load dll dynamically .But without adding the reference of the dll ,to avoid my C# application to load the dll from a particular place only.

Because due to following reason -
- i''m installing a software & it generates some dlls in it''s installation folder.
- Hence if installed multiple versions of same software, then maultiple versions of this dll will be generated in their respective installation folder.

- so my requirement is that, my C# application''ll decide from which location the dll need to loaded if multiple software installation is there(as above)

so everything will be happen at runtime.

PLease guide me soon.

Thanks

推荐答案

要回答问题本身:使用Accessmbly.Load [ ^ ],请参阅:我们反射在C#中运行时加载未引用的程序集 [ ^ ]



但是:

1)框架有它''找到assamblies的机制,请参阅: http://msdn.microsoft.com /en-us/library/yx7xezcf(v=vs.100).aspx [ ^ ]

2)你可以用强名称绑定对assambly的引用,因此,版本可以简单共存于gac

3)你可以使用插件框架
To answer to the question itself: use Assambly.Load[^], see: Using Reflection to load unreferenced assemblies at runtime in C#[^]

But:
1) the framework has it''s mechanism to locate assamblies, see: http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.100).aspx[^]
2) you can bind the reference to the assambly with strong name, thus, the versions could simply coexist in gac
3) There are plugin frameworks you can use


这篇关于从C#代码加载动态托管DLL的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆