I use third party library in my project. Call it like MainLibNET.dll
. I added this library in References
of my project. This dll has dependencies with other dlls. This other dlls I can't add in References
because they are native. I put this other libraries in \bin
but when I start my project I get error:
Could not load file or assembly 'MainLibNET.dll' or one of its dependencies
MainLibNET.dll can't find its dependencies because when site starts the server returns MainLibNET.dll not from \bin
but from here:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\e9b9d054\ddfaf4f8\assembly\dl3\8e683e03\00c3703b_919bcb01\MainLibNET.dll
and there are no other files in this folder except MainLibNET.dll. If I copy other dlls in this folder it works fine.
What can I do with my project or with anything else to make my project work without hand-copying?
Managed assemblies get shadow copied by ASP.NET. This process doesn't include unmanaged libraries which explains why they cannot be resolved. One possibility is to add those native libraries into the
c:\windows\System32\Inetsrv
folder. Another possibility is to put them into a folder which is part of thePATH
environment variable.I followed option 2a (1c) as mentioned in this blog, and it works beautifully.
In Visual Studio, right click the project and Add Existing Items for each native DLL
Right click each added DLL and choose Properties; set Build Action=Content and Copy to Output Directory = Copy Always. This will cause VS to copy files to bin directory.
Add following code to Global.asax, so ASP.NET will know where to look for the native DLLs.
.