0

我有一个动态加载 dll 的应用程序。应用程序和 dll 使用 Functions.dll,它可以是应用程序和每个 dll 的不同版本,但在执行中,应用程序和 dll 都使用相同的 dll 版本(EXE 使用的那个)并共享静态变量...

我如何强制他们使用自己的 Functions.dll(n 版本)?

-细节:

  • 我尝试通过“Assembly dll = Assembly.LoadFile(”和“Assembly dll=domaindll.Load(”加载 dll
  • 在 Functions.dll 中,所有方法和对象都是静态的
  • 我在所有情况下都不是动态地通过 VS 引用 Functions.dll 来“静态地”使用它
  • dll 和 Functions.dll 也是用 C# 开发的

- 文件夹结构:

应用:

Application.EXE
Functions.dll(version 1.2)
DLLS:
    EXAMPLEDLL1:
        EXAMPLEDLL1.DLL
        Functions.dll(version 1.1)
    EXAMPLEDLL2:
        EXAMPLEDLL2.DLL
        Functions.dll(version 1.0)
    EXAMPLEDLL3:
        EXAMPLEDLL3.DLL
        Functions.dll(version 1.2)
4

3 回答 3

4

您可以通过对其进行强签名来强制绑定到特定版本的 DLL。您也可以尝试在引用属性上将“特定版本”设置为 true,但据我所知,这只会影响编译时绑定,如果程序集不是强签名的,则可以在运行时加载不同的版本。

这应该可以帮助您入门:托管应用程序的强名称签名

但是请注意,在此 dll 中声明的任何类型都不会与不同版本的程序集中的相同类型进行类型等效。例如,如果我声明一个名为Fooin的类Functions.dll,则Foo1.0 版的实例与Foo1.1 版的实例的类型不同。就 CLR 而言,这些是完全不同的类型。

If all you have are static functions in the assembly and no types are defined, then you should be OK. Otherwise you need to look into a different approach.

于 2009-06-10T15:00:06.337 回答
0

To be able to do that I think you'll have to load your (Example) DLLs into separate AppDomains. Making cross-AppDomain calls incurs a bit of a performance penalty, but that is kinda unavoidable in the scenario you highlight.

于 2009-06-10T15:00:24.013 回答
0

At the end I solved it renaming the Functions.dll to match the EXAMPLEDLL that uses it....Ex: Application.EXE-->FunctionsApplication.dll EXAMPLEDLL1.dll-->FunctionsEXAMPLEDLL1.dll Thanks for the answers anyway..

Postdata: In another case where I could sign correctly the dlls i think Adam Robinson answer would be the correct one(and jerryjvl the second anwser).

于 2009-06-15T07:00:50.567 回答