Spook
Spook

Reputation: 25927

Native dependencies in .NET web app doesn't load

Say, that we have the following application structure.

The problem is, that after starting the web app I'm getting classic error:

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

Application is running on IIS Express and unfortunately attempts to find out where system searches for this DLL failed, I'm getting no results there.

The obvious, but dirty solution is to put DLLs somewhere and include that somewhere to system PATH. I'm searching for a better solution either to:

Is one of the solutions possible? How to approach using native libraries in .NET MVC projects?


Update: I do have DLLs in bin folder. But for some reason, one of assemblies is pushed to the following folder during run:

C:\Users\spook\AppData\Local\Temp\Temporary ASP.NET Files\vs\331a8458\b4c79531\assembly\dl3\0ae2569e\f3fde60f_7643d401

Since it's the only file in this folder, system cannot reach its dependencies, which are in bin folder and thus the failure. So the question is: why this file lands in the Temporary ASP.NET Files instead of being loaded from bin folder?

Upvotes: 3

Views: 1149

Answers (2)

Spook
Spook

Reputation: 25927

The problem was shadow copy mechanism. It caused the assembly, which had native dependencies to be copied to Temporary ASP.Net files folder - thus separating it from required binaries, which were in the bin folder.

I found solution here: http://faithlife.codes/blog/2013/05/using-native-dlls-from-asp-net-apps/ . In a nutshell, add the following to the web.config to disable shadow copy mechanism:

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

The other solution is to add folder with binaries to system PATH, but that was something I wanted to avoid.

Upvotes: 6

Nitin S
Nitin S

Reputation: 7591

You have to add reference to the MyAppDataProcessor.dll in your MyApp.Web project.

The dll MyAppDataProcessor.dll is not present in the bin directory of MyApp.Web that is why you are getting the error.

Upvotes: 0

Related Questions