Visual Studio 2015 即使在 bin 文件夹中复制后也找不到外部 .dll,但只有在复制到 c:\Windows\

Visual Studio 2015 does not find external .dll even after copying in bin folder, but only after copying to c:\Windows\

我尝试在 Visual Studio 2015 年构建一个 Web 项目,它引用了一个 c# .dll-project "dotnetWrapper",它是一个 c++ 项目 "managedDllWrapper" 的 c# 包装器,其中包括一些第 3 方 64 位原生 C++ .dll.

.Net Framework 4.6.1 和 x64 上的引用项目和 Web 项目 运行。 VS2015使用iis express 64位

编译一切正常。

当我在 VS2015 中启动本地网络服务器时(点击绿色启动按钮),我收到错误消息,指出找不到 "managedDllWrapper.dll" 或其依赖项之一:

Server Error in '/' Application.

Could not load file or assembly 'managedDllWrapper.DLL' or one of its dependencies. The specified module could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'managedDllWrapper.DLL' or one of its dependencies. The specified module could not be found.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FileNotFoundException: Could not load file or assembly 'managedDllWrapper.DLL' or one of its dependencies. The specified module could not be found.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0

System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +234

System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +108

System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +25

System.Reflection.Assembly.Load(String assemblyString) +34 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49

[ConfigurationErrorsException: Could not load file or assembly 'managedDllWrapper.DLL' or one of its dependencies. The specified module could not be found.]

System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +772

System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +259

System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +163

System.Web.Compilation.<>c.b__143_0(AssemblyInfo ai) +29

System.Linq.d__16'2.MoveNext() +293

System.Linq.d__66'1.MoveNext() +100

System.Linq.d__63'1.MoveNext() +73

System.Web.UI.Util.GetTypeFromAssemblies(IEnumerable assemblies, String typeName, Boolean ignoreCase) +217

System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +266

System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type) +48

System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +17

System.Web.Configuration.HandlerFactoryCache..ctor(String type) +25

System.Web.HttpApplication.GetFactory(String type) +104

System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +262

System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0

请注意,本机 dll(依赖项)位于 web-project bin 文件夹中(手动复制)。

当我将本机 dll 复制到我的 C:\Windows\ 文件夹时,Web 应用程序运行顺利且正常。不知何故,web 应用程序的 dll 搜索路径仅指向 C:\Windows\ 文件夹,但它也应该查看 webapp 执行 (bin) 文件夹,对吗?

当我不做 Web 应用程序,而是做 C# 控制台测试应用程序时,它还包括所有 dll 的包装器,将 dll 复制到 test-app bin 文件夹中工作正常,应用程序运行秒。只有web-application有这个问题,不接受其bin文件夹中的dll。

此外,当我将 dll 复制到 C:\Windows\ 目录和 运行 网络应用程序,然后再次尝试删除 dll 时,它说它们不能已删除,因为

because the file is open in IIS Express Worker Process.

所以,也许这是 IIS 的问题而不是 VS2015 的问题,但我无法配置 IIS(或者我不知道如何配置)。我使用 Visual Studio 2015.

附带的 IIS Express

我在 Google 和 Whosebug 中的所有研究结果:

如果我的 web 项目可以在与 C:\Windows\ 不同的文件夹中找到 .dll,我会很高兴,因为我怀疑我是否会被允许将 17 .dll 添加到C:\Windows\ MS azurewebsites 上的文件夹,当我想发布网站时。然后,路径应该以某种方式位于应用程序文件夹中。

我没有一对一解决问题,但是我成功规避了问题:

通过使用显式 dllimport 重写 c#/c++ 包装器,我直接使用路径寻址 dll 文件。然后,依赖的 dll 只需与引用的 dll 位于同一文件夹中。这也适用于网络应用程序。