简体   繁体   English

即使在bin文件夹中复制后,Visual Studio 2015仍找不到外部.dll,而仅在复制到c:\\ Windows \\

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

I try to build a Web-project in Visual Studio 2015 which references ac# .dll-project "dotnetWrapper" which is ac# wrapper for a c++ project "managedDllWrapper" which includes some 3rd-party 64-bit native c++ .dll. 我尝试在Visual Studio 2015中构建一个Web项目,该项目引用ac#.dll项目“ dotnetWrapper”,这是c ++项目“ managedDllWrapper”的ac#包装器,其中包括一些第三方的64位本机c ++ .dll。

The referenced projects and the Web-project run on .Net Framework 4.6.1 and x64. 引用的项目和Web项目在.Net Framework 4.6.1和x64上运行。 VS2015 uses iis express 64 bit. VS2015使用iis Express 64位。

Everything compiles fine. 一切都编译良好。

When I start the local webserver in VS2015 (hit the green start button), I get the error message that that the "managedDllWrapper.dll" or one of its dependencies could not be found: 当我在VS2015中启动本地Web服务器时(单击绿色的“开始”按钮),我收到一条错误消息,即找不到“ managedDllWrapper.dll”或其依赖项之一:

Server Error in '/' Application. “ /”应用程序中的服务器错误。

Could not load file or assembly 'managedDllWrapper.DLL' or one of its dependencies. 无法加载文件或程序集“ managedDllWrapper.DLL”或其依赖项之一。 The specified module could not be found. 指定的模块无法找到。

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 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. 异常详细信息:System.IO.FileNotFoundException:无法加载文件或程序集“ managedDllWrapper.DLL”或其依赖项之一。 The specified module could not be found. 指定的模块无法找到。

Source Error: 源错误:

An unhandled exception was generated during the execution of the current web request. 当前Web请求的执行期间生成了未处理的异常。 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. [FileNotFoundException:无法加载文件或程序集'managedDllWrapper.DLL'或其依赖项之一。 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._nLoad(AssemblyName文件名,字符串codeBase,证据AssemblySecurity,RuntimeAssembly locationHint,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,布尔型throwOnFileNotFound,布尔值用于Introspection,布尔值hibitSecurityChecks)

System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +234 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,证据AssemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,布尔型throwOnFileNotFound,布尔型用于自省,布尔型抑制安全检查)+234

System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +108 System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,证据AssemblySecurity,StackCrawlMark&stackMark,IntPtr pPrivHostBinder,用于自省的布尔值)+108

System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +25 System.Reflection.RuntimeAssembly.InternalLoad(字符串assemblyString,证据assemblySecurity,StackCrawlMark&stackMark,用于自省的布尔值)+25

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

[ConfigurationErrorsException: Could not load file or assembly 'managedDllWrapper.DLL' or one of its dependencies. [ConfigurationErrorsException:无法加载文件或程序集'managedDllWrapper.DLL'或其依赖项之一。 The specified module could not be found.] 指定的模块无法找到。]

System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +772 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串assemblyName,布尔型starDirective)+772

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

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

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

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

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

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

System.Web.UI.Util.GetTypeFromAssemblies(IEnumerable assemblies, String typeName, Boolean ignoreCase) +217 System.Web.UI.Util.GetTypeFromAssemblies(IEnumerable程序集,字符串typeName,布尔值ignoreCase)+217

System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +266 System.Web.Compilation.BuildManager.GetType(字符串类型名称,布尔throwOnError,布尔ignoreCase)+266

System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type) +48 System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(字符串类型)+48

System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +17 System.Web.Configuration.HandlerFactoryCache.GetHandlerType(字符串类型)+17

System.Web.Configuration.HandlerFactoryCache..ctor(String type) +25 System.Web.Configuration.HandlerFactoryCache..ctor(字符串类型)+25

System.Web.HttpApplication.GetFactory(String type) +104 System.Web.HttpApplication.GetFactory(字符串类型)+104

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

System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值和已完成同步)+137

Version Information: Microsoft .NET Framework Version:4.0.30319; 版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET Version:4.6.1055.0 ASP.NET版本:4.6.1055.0

Note that the native dlls (the dependencies) are in the web-project bin folder (copied manually). 请注意,本机dll(依赖项)位于Web项目的bin文件夹(手动复制)中。

When I copy the native dlls into my C:\\Windows\\ folder, the web application works smoothly and fine. 当我将本机dll复制到我的C:\\ Windows \\文件夹中时,Web应用程序可以正常运行。 Somehow, the web-application's dll search path points only to the C:\\Windows\\ folder, but it should also look into the webapp execution (bin) folder, right? 以某种方式,Web应用程序的dll搜索路径仅指向C:\\ Windows \\文件夹,但是它也应该查看webapp执行(bin)文件夹,对吗?

When I don't do a web-application, but a C# console test-application, which also includes the wrapper with all dlls, the copying of the dlls into the test-app bin folder works fine and the application runs. 当我不使用Web应用程序,而是使用C#控制台测试应用程序(该程序还包括所有dll的包装程序)时,将dll复制到test-app bin文件夹中就可以正常工作,并且该应用程序可以运行。 Only the web-application has this problem, not to accept the dlls in its bin folder. 仅Web应用程序有此问题,不接受其bin文件夹中的dll。

Also, when I copy the dlls into the C:\\Windows\\ directory, and run the web-application, and then try to delete the dlls again, it says they cannot be deleted because 另外,当我将dll复制到C:\\ Windows \\目录中,并运行Web应用程序,然后尝试再次删除dll时,它说无法删除它们,因为

because the file is open in IIS Express Worker Process. 因为该文件是在IIS Express工作进程中打开的。

So, maybe it is a problem of the IIS and not of VS2015, but I cannot configure my IIS (or I don't know how). 因此,也许这是IIS的问题,而不是VS2015的问题,但是我无法配置IIS(或者我不知道如何)。 I use the IIS express which comes with Visual Studio 2015. 我使用Visual Studio 2015随附的IIS Express。

All my research in Google and stackoverflow resulted in: 我在Google和stackoverflow上所做的所有研究均得出:

  • copy dlls to bin folder (tried, but does not work as described above, only works for a C# console app, but not for a web-app). 将dll复制到bin文件夹(尝试过,但如上所述无法运行,仅适用于C#控制台应用程序,不适用于Web应用程序)。
  • reference dlls directly in the project (not possible:) 直接在项目中引用dll(不可能:)

    "[..].dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component." “无法添加[..]。dll。请确保该文件可访问,并且它是有效的程序集或COM组件。”

  • check if everything is 64-bit, and same .Net version (checked, 64 bit, .Net 4.6.1. Also: it works fine for a console app, but not web-app). 检查所有内容是否都是64位和相同的.Net版本(已检查,64位,.Net 4.6.1。此外:它对于控制台应用程序正常工作,但不适用于Web应用程序)。
  • change the web.config to add further .dll folders. 更改web.config以添加其他.dll文件夹。 But this did not help either. 但这也没有帮助。

I would be happy if the .dll could be found by my web-project in a different folder than C:\\Windows\\ , since I doubt I will be allowed to add 17 .dll to the C:\\Windows\\ folder on MS azurewebsites when I want to publish the site. 如果我的Web项目可以在不同于C:\\ Windows \\的文件夹中找到.dll,我会很高兴,因为我怀疑是否可以将17 .dll添加到MS azurewebsites的C:\\ Windows \\文件夹中当我想发布该网站时。 Then, the path should be somehow within the application folders. 然后,路径应以某种方式位于应用程序文件夹中。

I did not solve the problem one to one, but I circumvented the problem successfully: 我没有一对一地解决问题,但是我成功地绕过了这个问题:

By rewriting the c#/c++ wrapper with explicit dllimport, I adressed the dll files directly with path. 通过用显式的dllimport重写c#/ c ++包装器,我直接用路径处理了dll文件。 Then, the dependent dll just have to be in the same folder as the referenced dll. 然后,从属dll只需与引用的dll位于同一文件夹中。 This works also in web apps. 这在Web应用程序中也适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将projectname.dll文件从我的Visual Studio项目复制到IIS bin文件夹中是正确的 - Copying the projectname.dll file from my visual studio project to my IIS bin folder is this correct 停止Visual Studio将数据库MDF复制到bin - Stop Visual Studio Copying Database MDF to bin 在发布过程中从bin文件夹复制动态复制的DLL - Copying dynamically copied DLL's from bin folder during publish DLL引用没有复制到项目bin中 - DLL reference not copying into project bin 在解决方案中复制项目并更新名称空间-Visual Studio 2015 - Copying a project in a solution and updating namespaces - Visual studio 2015 Visual Studio构建解决方案不会将dll复制到bin文件夹,但是构建项目可以 - Visual Studio building solution does not copy dll to bin folder, but building project does Visual Studio不刷新bin文件夹 - Visual studio does not refresh the bin folder Visual Studio 2015 - 片段后的C#换行符 - Visual Studio 2015 - C# line break behavior after snippets 有没有一种方法可以通过将dll复制到bin中来消耗事件? - Is there a way to consume events just by copying a dll into bin? Visual Studio:使用外部文件(不复制它们) - Visual Studio: Using external files (without copying them)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM