【发布时间】:2013-06-24 08:22:52
【问题描述】:
我正在为 WCF 服务开发 ASP.NET 主机。该服务引用一个 C++/CLI 包装库,该库本身引用一个非托管 DLL。基于this question,我在 ASP.NET DLL 中嵌入了非托管 DLL。然后我像这样提取它:
string[] dlls = new [] { "myDLL.dll", "myDLLD.dll" };
Assembly assembly = Assembly.GetExecutingAssembly();
string location = Path.GetDirectoryName(assembly.Location);
Dictionary<string, Stream> streams =
(from dll in dlls
select new KeyValuePair<string, Stream>(
dll, assembly.GetManifestResourceStream(typeof(Global), dll)))
.ToDictionary(p => p.Key, p => p.Value);
foreach (KeyValuePair<string, Stream> stream in streams)
{
using (FileStream file = new FileStream(Path.Combine(location, stream.Key),
FileMode.Create))
{
stream.Value.CopyTo(file);
}
}
我已尝试将此代码放入 Application_Start() 中的 Global.asax.cs 和 AppInitialize() 中的 App_Code 文件夹中,但在这两种情况下,我都会收到关于包装 DLL 或其一个在任一函数中遇到断点之前无法加载依赖项。我可以打断点的唯一方法是将非托管 DLL 放置在系统路径中的某个位置(例如C:\Windows\system),但这显然违背了首先嵌入 DLL 的目的。在 ASP 开始查找之前,如何获取 DLL 所需的位置?
【问题讨论】:
-
也许引用非托管DLL的托管DLL也应该被嵌入。 ASP.NET 不执行按需链接:
bin中的任何内容都尝试“立即”加载和链接。
标签: asp.net wcf dll c++-cli unmanaged