使用多个版本的同一个DLL [英] Using multiple versions of the same DLL

查看:240
本文介绍了使用多个版本的同一个DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在负责创建一个应用一个新的模块,所以,我加入新的DLL到项目中。这是一切优秀和幸福。

I've been tasked in creating a new module for an application, and so, I'm adding new DLLs to the project. This is all fine and well.

不过,在我的DLL我想使用外部的DLL的新版本(在这我管不着)。如果我只是引用了新的DLL,并与一个只工作,我的code的工作,但旧的code将停止运行。

However, in my DLLs I'd like to use a new version of an external DLL (over which I have no control). If I just reference the new DLL and work with that one only, my code will work, but the old code will stop functioning.

Could not load file or assembly 'itextsharp, Version=5.0.6.0, Culture=neutral,
PublicKeyToken=8354ae6d2174ddca' or one of its dependencies. The located assembly's
manifest definition does not match the assembly reference. (Exception from HRESULT:
0x80131040)

我试着改变的DLL名称的简单的技巧,但是这显然有点太天真的我,认为这是可行的。我已经使用外部别名(定义他们在我的参考文献)试过,但我还是不知道该如何得到两个文件具有相同的名称为一个BIN文件夹...

I've tried a simple trick of changing the DLLs name, but that apparently was a bit too naive of me, to think it would work. I've tried using the external aliases (by defining them in my references), but I still don't know how to get two files with the same name into one BIN folder...

我应该怎么办?

推荐答案

可以的加载另一个版本为特定的AppDomain

可能太详细了,但在这里是一个说明在一个有用的设置使用的AppDomain的一篇文章,以及它们是如何工作的:

Possibly too detailed, but here is an article that demonstrates the use of AppDomains in a useful setting and how they work:

http://msdn.microsoft.com/en-us/magazine/ cc164072.aspx

在一个非常基本的意义上,它归结为样本code:

In a very basic sense it comes down to this sample code:

    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    ...

    static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        if (/*some condition*/)
            return Assembly.LoadFrom("DifferentDllFolder\\differentVersion.dll");
        else
            return Assembly.LoadFrom("");
    }

这篇关于使用多个版本的同一个DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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