单个进程中多个同名的DLL [英] Multiple Dll of same name in single process

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

问题描述

我遇到了Dell-hell架构问题,想找到解决方案:

I encountered a Dll-hell architectural issue and would like to find solution:

我有一个用C#编写的应用程序,我们称它为App.exe.

I have an application written in C#, let’s call it App.exe.

此应用程序依赖于另一个托管dll:Managed.dll.
App.exe也依赖于非托管dll–这是旧版二进制文件:Unmanaged.dll
当前是使用DllImport属性加载此unmanaged.dll的.

This app depends on another managed dll: Managed.dll.
App.exe also depends on an unmanaged dll – which is a legacy binary: Unmanaged.dll
This unmanaged.dll is currently loaded using DllImport attribute.

现在最大的问题是在Managed.dll和Unmanaged.dll下.有许多旧版dll–所有这些都是在不受管的世界中用C/C ++编写的,并由Managed.dll和Unmanaged.dll共享.大部分实际上是兼容的(目前),但是我们已经 确认有1个实例不是.

Now the big problem is underneath the Managed.dll and Unmanaged.dll. There are many legacy dlls – all written with C/C++ in unmanaged world, being shared by Managed.dll and Unmanaged.dll. Most are actually compatible (for now), but we have already identified 1 instance that it’s not.

让我们说不兼容的一个叫做A.dll. A.dll并非直接由Managed.dll或Unmanaged.dll调用,而是由Managed.dll和Unamanaged.dll使用的其他一些dll实际引用.由于在单个进程中仅加载了dll 一次,我们的应用程序的行为会有所不同(错误),具体取决于Managed.dll或Unmanaged.dll加载到内存的顺序.

Let’s say the incompatible one is called A.dll. A.dll is not called directly by Managed.dll or Unmanaged.dll, instead they are actually referenced by some other dll used by Managed.dll and Unamanaged.dll. Since in a single process a dll is loaded only once, our app behaves differently (wrongly) depending on the order Managed.dll or Unmanaged.dll are loaded into memory.

无法替换/重写旧的二进制文件.现在,我们唯一的替代方法是创建两个进程:一个包含App.exe和Managed.dll.另一个过程是将unmanaged.dll及其从属dll包装到服务中.
如果可能的话,我想避免在现有代码中添加更多结构.

Replacing/Rewriting the old binaries is not possible. The only alternative we have now is to create two process: one to contain App.exe and the managed.dll. The other process is to wrap the unmanaged.dll and its dependent dlls into a service.
If possible I want to avoid adding more structure into existing code.

             App.exe
                |
        ------------------
        |                 |
Managed.dll           Unmanaged.dll
     |                      |
xxxx.dll                  yyyy.dll
     |                      |
A.dll ver 2              A.dll ver 1

文件夹结构:

- AppFolder                    App.exe
   - ManagedFolder         Managed.dll, xxxx.dll
   - UnmanagedFolder     Unmanaged.dll, yyyy.dll

经过阅读后,似乎并排可以解决此问题.

After some reading it seems that Side-by-side can solve this issue.

现在,我对动态加载dll时如何处理ActivationContext感到困惑.
我已经尝试为xxxx.dll和yyyy.dll创建清单(也尝试使用MT.exe进行嵌入)以依赖于A.dll版本1或2.但是它仍然无法找到A.dll
1. 据此( http://omnicognate.wordpress.com/2009/10 /05/winsxs )清单中的激活上下文将仅在dll加载期间使用.如果A.dll是动态的 已加载,则将使用系统默认激活上下文而不是xxxx.manifest,因为程序集激活上下文已关闭.
2.类似地,当yyyy.dll尝试加载A.dll时,只有将其放置在AppFolder中,它才能找到它.

Now I’m confused on how to handle ActivationContext if I load dlls dynamically.
I have tried to create manifest (and also tried to embed using MT.exe) for xxxx.dll and yyyy.dll to depend on A.dll version 1 or 2. But it’s still not able to find A.dll
1. According to this (http://omnicognate.wordpress.com/2009/10/05/winsxs) the activation context from manifest will only be used during the loading of dll. If A.dll is dynamically loaded, then system default activation context will be used instead of xxxx.manifest since the assembly activation context is already closed.
2. Similarly when yyyy.dll tries to load A.dll, it can only find it if it’s placed in the AppFolder.

问题:
假设我无法更改xxxx.dll和yyyy.dll:

Question:
Assuming I can’t change xxxx.dll and yyyy.dll:

1. 我应该如何强制" ISOLATION_AWARE’用于xxxx.dll和yyyy.dll?
是否可以将清单文件嵌入xxxx.dll和yyyy.dll的资源ID:ISOLATIONAWARE_MANIFEST_RESOURCE_ID中而无需重新编译它们?

1. How exactly should I force ‘ISOLATION_AWARE’ for xxxx.dll and yyyy.dll?
Is it possible to just embed the manifest in resource ID: ISOLATIONAWARE_MANIFEST_RESOURCE_ID of xxxx.dll and yyyy.dll without recompiling them?

2.如果我将清单文件嵌入Managed.dll和UnManaged.dll,这是否相同?

2. Does it mean the same if I embed the manifest in managed.dll and unmanaged.dll?

3.我可以在受管理的世界中使用自己的上下文管理吗?DllImport是否使用与C ++ dll搜索顺序相同的Dll搜索顺序?

3. Can I use own context management from within managed world? Does DllImport use the same Dll search order with C++ dll search order?

4.假设我在Managed.dll和Unmanaged.dll中管理自己的上下文管理,并在我自己的上下文处于活动状态时加载从属程序集.如何强制第二个LoadLibrary加载新的dll,而不是使用内存中已有的dll?

4. Let’s say I manage my own context management in Managed.dll and Unmanaged.dll, and load the dependent assemblies when my own context is active. How do I force the second LoadLibrary is loading a new dll instead of using the one already in memory?


 


 

推荐答案

您是否曾经考虑过使用其他AppDomain?可能吗?

Do you ever have considered to use different AppDomains? Is that possible?


这篇关于单个进程中多个同名的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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