Microsoft 应用程序块 DLL V2 和 V4.1 参考

发布于 2024-09-08 13:38:41 字数 980 浏览 2 评论 0原文

我的应用程序正在引用 Microsoft Enterprise 库 V4.1,而较旧的 DLL(外部应用程序)之一需要引用 Microsoft Enterprise 库 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,但是当我调用正在使用的外部 DLL 函数时,我仍然遇到以下异常V2.0.0.0组装:

...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)

My application is referencing Microsoft Enterprise library V4.1 while one of the older DLL (external application) requires a reference to Microsoft Enterprise library V2.0. I know for sure that i can register both of these assemblies in the GAC and the application will start reading relevant DLL as required but that is not a solution for us since our security expert is not agreeing upon accepting this solution.

Is there any way using the webconfig where I can specifically specify that the Older DLL use V2.0 while the entire application uses 4.V0.

note : We're using Asp.net visual Studio C#

Help needed desperately !
Thanks

Update :

Tried the solution of using privatePath probing :

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

My Web folder now has ExtDLL folder which contains V2.0.0.0 Dlls for Microsoft Enterprise library, but i still get the following exception as soon as i call the external DLL's function which is using V2.0.0.0 assembly:

...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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骷髅 2024-09-15 13:38:41

你尝试过这样的事情吗?目前,我使用这种技术来支持应用程序中的多个 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(这是一个构建示例
本地化的卫星程序集总是会像这样出现)

Have you tried something like this? This is currently the technique that I use for supporting multiple versions of DLL in an application, whilst avoiding the 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>

The make sure you have:

  1. Your DLLs are strongly named
  2. the appropriate directory structure (v1/MyLibrary.dll and v2/MyLibrary.dll) is in your binary folder
  3. None of the DLLs that appear in these 'subfolders' should appear directly within your binary folder.

This is a simple solution - but I would reccomend that you actuall name your subfolders the same are they would be in the GAC, such as:

./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 (this is an example of a build that is
localized, satellite assemblies would always appear like this)

ぽ尐不点ル 2024-09-15 13:38:41

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

我能够让它工作的唯一方法是使用 自定义解析程序集加载.

我将 2.0 程序集放置在应用程序 bin 目录中。然后我将 4.1 程序集放置在 bin 下名为 EL41 的目录中 (bin\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");
}

解析程序集,这肯定会起作用。您可以将路径放置在配置中以避免对位置进行硬编码,但我仍然感觉不对。我想知道是否有一种侵入性较小的方式来做你想做的事。

I was unable to be able to load both versions of Enterprise Library using probing/privatePath or codebase configuration.

The only way I was able to get it to work was using custom resolving of assembly loads..

I placed the 2.0 assemblies in the application bin directory. Then I placed the 4.1 assemblies in a directory called EL41 under bin (bin\EL41). I then added custom event handler to try to resolve the assembly by adding

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

to startup code and then creating the 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");
}

This definitely will work. You could place the path in configuration to avoid hard coding the location but it still feels wrong to me. I wonder if there is a less intrusive way to do what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文