【问题标题】:Microsoft Application block DLL V2 and V4.1 referencesMicrosoft 应用程序块 DLL V2 和 V4.1 参考
【发布时间】:2010-07-06 20:48:53
【问题描述】:

我的应用程序正在引用 Microsoft Enterprise library V4.1,而旧的 DLL(外部应用程序)之一需要对 Microsoft Enterprise library V2.0 的引用。我确信我可以在 GAC 中注册这两个程序集,并且应用程序将根据需要开始读取相关的 DLL,但这不是我们的解决方案,因为我们的安全专家不同意接受此解决方案。

有什么方法可以使用 webconfig,我可以明确指定旧 DLL 使用 V2.0,而整个应用程序使用 4.V0。

注意:我们使用的是 Asp.net Visual Studio C#

急需帮助! 谢谢

更新:

尝试了使用privatePath探测的解决方案:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <probing privatePath="bin;ExtDLL"/>
    </assemblyBinding>

我的 Web 文件夹现在有 ExtDLL 文件夹,其中包含 Microsoft Enterprise 库的 V2.0.0.0 Dlls,但是当我调用使用 V2.0.0.0 程序集的外部 DLL 函数时,我仍然得到以下异常:

...System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

【问题讨论】:

    标签: .net assemblies reference versioning enterprise-library


    【解决方案1】:

    你尝试过这样的事情吗?这是目前我用来在应用程序中支持多个版本的 DLL,同时避免 GAC 的技术。

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MyLibrary" publicKeyToken="605f591b87e816bd"/>
        <codeBase version="1.0.0.0" href="./v1/MyLibrary.dll"/>
        <codeBase version="2.0.0.0" href="./v2/MyLibrary.dll"/>
      </dependentAssembly>
    </assemblyBinding>
    

    确保你有:

    1. 您的 DLL 具有强名称
    2. 相应的目录结构(v1/MyLibrary.dll 和 v2/MyLibrary.dll)在您的二进制文件夹中
    3. 出现在这些“子文件夹”中的任何 DLL 都不应直接出现在您的二进制文件夹中。

    这是一个简单的解决方案 - 但我建议您将子文件夹命名为与它们在 GAC 中的名称相同,例如:

    ./MyLibrary/1.0.0.0__605f591b87e816bd/MyLibrary.dll

    ./MyLibrary/2.0.0.0__605f591b87e816bd/MyLibrary.dll

    ./MyLibrary/2.0.0.0_en_605f591b87e816bd/MyLibrary.dll(这是一个构建示例 本地化,附属程序集总是这样)

    【讨论】:

      【解决方案2】:

      我无法使用 probing/privatePath 或代码库配置加载两个版本的企业库。

      我能够让它工作的唯一方法是使用custom resolving of assembly loads.

      我将 2.0 程序集放在应用程序 bin 目录中。然后我将 4.1 程序集放在 bin (bin\EL41) 下名为 EL41 的目录中。然后我添加了自定义事件处理程序以尝试通过添加来解决程序集

      AppDomain.CurrentDomain.AssemblyResolve += newResolveEventHandler(MyResolveEventHandler);
      

      启动代码,然后创建 MyResolveEventHandler

      private static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
      {
          string[] assemblyInfo = args.Name.Split(',');
          return Assembly.LoadFrom(@"file:///C:/Documents and Settings/My Documents/Visual Studio 2008/Projects/App/bin/EL41/" + assemblyInfo[0] + ".dll");
      }
      

      这肯定会奏效。您可以将路径放在配置中以避免对位置进行硬编码,但对我来说仍然感觉不对。我想知道是否有一种不那么侵入性的方式来做你想做的事。

      【讨论】:

        猜你喜欢
        • 2011-07-10
        • 1970-01-01
        • 1970-01-01
        • 2010-11-17
        • 1970-01-01
        • 2010-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多