c# - Web API 无法引用 DLL

标签 c# asp.net iis dll asp.net-web-api

我有一个 .Net 4.5 项目,它已构建为 64 位 DLL,需要包含在我的 Web API 项目中。 Web API 项目也构建为 64 位。无论我尝试什么,我总是收到异常“无法加载文件或程序集 '*.DLL' 或其依赖项之一。找不到指定的模块。”。此 DLL 是从一个混合模式项目创建的,该项目包含一个非托管 C++ 项目和一个使用/clr 编译的 C++/CLI 包装器。

我已使用 DependencyWalker 检查并确保所有依赖项 DLL 与 Web API 项目以及 bin 文件夹位于同一文件夹中。我还检查了位数以确保它们都是 64 位的。然后我创建了一个 C# 控制台项目,它加载了这个 DLL 及其依赖项,一切正常。

我的 Web API 项目使用本地 IIS 6.2 服务器,应用程序池使用默认标识 (ApplicationPoolIdentity)。即使我将身份更改为 NetworkService,它仍然失败。在这一点上,我不知道如何进一步调试。我之前使用过 Process Monitor 来确定丢失的 DLL,但不确定如何将它与 Web API 一起使用。对于如何处理此问题的任何建议,我们将不胜感激。

编辑 - 这是 Fusion 日志:

The operation was successful. Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll Running under executable c:\windows\system32\inetsrv\w3wp.exe --- A detailed error log follows.

=== Pre-bind state information === LOG: DisplayName = TestBridge (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: TestBridge | Domain ID: 12 WRN: A partial bind occurs when only part of the assembly display name is provided. WRN: This might result in the binder loading an incorrect assembly. WRN: It is recommended to provide a fully specified textual identity for the assembly, WRN: that consists of the simple name, version, culture, and public key token. WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. LOG: Appbase = file:///D:/build/MSVC/ImageSearchService/ LOG: Initial PrivatePath = D:\build\MSVC\ImageSearchService\bin LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\imagesearchservice\d0503829 LOG: Cache Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\imagesearchservice\d0503829 LOG: AppName = 7ee35914 Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: D:\build\MSVC\ImageSearchService\web.config LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/imagesearchservice/d0503829/7ee35914/TestBridge.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/imagesearchservice/d0503829/7ee35914/TestBridge/TestBridge.DLL. LOG: Attempting download of new URL file:///D:/build/MSVC/ImageSearchService/bin/TestBridge.DLL. LOG: Assembly download was successful. Attempting setup of file: D:\build\MSVC\ImageSearchService\bin\TestBridge.dll LOG: Entering download cache setup phase. LOG: Assembly Name is: TestBridge, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy. LOG: Using application configuration file: D:\build\MSVC\ImageSearchService\web.config LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Binding succeeds. Returns assembly from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\imagesearchservice\d0503829\7ee35914\assembly\dl3\584c8f8c\64f0e4b3_4a53cf01\TestBridge.dll. LOG: Assembly is loaded in default load context.

最佳答案

作为 VS 2013/2015/2017 的一部分,您可能需要启用 64 位 IIS Express 支持:

Tools -> Options -> Projects and Solutions -> Web Projects -> Use the 64 bit version of IIS Express

归功于此 question 中的回复

关于c# - Web API 无法引用 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22925009/

相关文章:

c# - Moq 4.13.1 与 Task.Extensions 不兼容

c# - SQL 服务器 2008 : update increment logic difficulty

c# - 为什么我不能在同一个类上使用 WCF DataContract 和 ISerializable?

c# - javascript中设置的标签文本未在服务器端显示标签文本

ASP.NET:CSS 友好的日历控件

c# - 如何创建二叉树

c# - Web.UI 的 InvokeRequired 需要帮助

asp.net-mvc - 将 EF 4.1 代码优先 ASP.NET MVC3 部署到中等信任共享主机

asp.net - HTTP 错误 503。该服务在简单的 ASP.NET 4.0 网站下不可用

.net - 根据数据库刷新刷新缓存