sztepen
sztepen

Reputation: 133

Could not load file or assembly - not working on asp, works on desktop

While using a native dll dependency on a asp.net web project and debugging in VS2015 with IIS express I'm getting the dreaded:

Could not load file or assembly 'XXX.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 'XXX.DLL' or one of its dependencies. The specified module could not be found.

HOWEVER the same dependency works fine in a simple forms app on the same machine - hence I assume all the dependencies and co-dependencies are present

maybe you have some clues, how can this be?

What I already tried:

some details:

VS2015 Community, running on an Azure VM with Windows Server 2012 (test system), clean install

the app uses CGAL and BOOST libraries (c++).

'Dependency tree' is as follows: C# wrapper references a CLR C++ project which in turn references the native C++ (only this one uses CGAL/Boost);

The C# wrapper is then used in the forms app (works) or the asp.net web app (doesn't work);

Putting Cgal dlls (around 6 files) into the bin output folder was enough to run the forms app.

PS: of course on my 2 dev machines (Win 7, Win 10) the asp.net project works swimmingly - but these contain dedicated installs of the huge c++ references.

PPS: I currently really prefer to use iis express due to external reasons. I have to simulate deploying the app on a clean-ish Win10 laptop, in a dev environment, with minimal external installations

PPPS it seems the win10 dev machine isn't working after all - edit: this was the key clue, see my answer below and Ho do I reference native files in IIS express?

I'm a bit stuck right now, thanks.

Upvotes: 1

Views: 2108

Answers (1)

sztepen
sztepen

Reputation: 133

Solution: on Win 10 I copied the dll output (\bin folder) into the Program Files (x86)\IIS Express folder (as I am using the 32-bit version).

Apparently, this wasn't needed on Win7 - I will have to investigate why

I found this solution in: Ho do I reference native files in IIS express?

EDIT: another, more elegant (?) solution is to disable shadow-copying in web.config as in http://faithlife.codes/blog/2013/05/using-native-dlls-from-asp-net-apps/

"The simplest solution I’ve found is to turn off shadow copying, which causes the DLLs to be loaded directly from the bin directory.(...) Just add a hostingEnvironment element to your web.config:"

<configuration>
 ...
  <system.web>
    ...
    <hostingEnvironment shadowCopyBinAssemblies="false" />

Upvotes: 3

Related Questions