简体   繁体   中英

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.

The referenced projects and the Web-project run on .Net Framework 4.6.1 and x64. VS2015 uses iis express 64 bit.

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:

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

Note that the native dlls (the dependencies) are in the web-project bin folder (copied manually).

When I copy the native dlls into my C:\\Windows\\ folder, the web application works smoothly and fine. 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?

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. Only the web-application has this problem, not to accept the dlls in its bin folder.

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

because the file is open in IIS Express Worker Process.

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). I use the IIS express which comes with Visual Studio 2015.

All my research in Google and stackoverflow resulted in:

  • 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).
  • reference dlls directly in the project (not possible:)

    "[..].dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

  • 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).
  • change the web.config to add further .dll folders. 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. 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. Then, the dependent dll just have to be in the same folder as the referenced dll. This works also in web apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM