2

Backgroud:

I am in the process of migrating a console application to be part of our existing web API project. All development work is done on Visual Studiod 2015 (with IIS Express). The application uses few third party datasource api DLLs to grab data from that datasource. All these DLLs are managed by our internal nuget package sources.

Issue:

Now the console application runs fine and can load up the those DLLs. I copied across the logic into my web project and added the DLLs via nuget. Solution builds but got the following error when starting up the web project:

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

Where ABC.DLL is one of the third party DLLs.

I have done the following:

  • Confirm ABC.DLL is in the bin folder of my web project
  • Changed target build platform of my web project to be x86 and unchecked "Use 64 bit version of IIS Express for websites and project" setting in VS2015 (the third party dll is 32-bit)
  • Ran dumpbin.exe on ABC.DLL's dependency and got XYZ.dll,MSVCR120.dll,KERNEL32.dll,MSVCP120.dll,mscoree.dll

Regarding to the last step, those dlls were all missing in the bin folder (but the last 4 DLLs should be in system32 win directory so shouldn't matter?)

As for XYZ.dll, it is another third party library and is located on C:\Program Files (x86)\XYZ\ folder. I manually copied it across to the web project bin folder (in fact copied across all Dlls inside XYZ folder) and still get the same issue.

Questions

  • What am I missing here? The console app obviously can load ABC.DLL but the web project can't. Appreciate it if you can tell me what to check next.
  • The error message from start up web page is not very useful, is there a way to find out where the web project is trying to load the third party DLLs?

Thank you in advance!

user10301180
  • 23
  • 2
  • 5
  • Since you are running 32 bit, you should make sure all five native dependencies are available via system Path. And in your case, verify `MSVCR120.dll` and `MSVCP120.dll` are in `%windir%\sysWOW64`, and you might also copy `XYZ.dll` there. – Lex Li Aug 31 '18 at 18:48

2 Answers2

0

Simply adding external DLLs to your Bin folder is not a great idea. Files can disappear from this folder for various reasons, such as your team members deleting a seemingly useless DLL, or through Visual Studio clearing it. Also, the output DLLs from referenced projects in your solution, would end up there, and are replaced every time you build your project.

What you should do for third-party DLLs, is create some "dependencies" folder in, or close to, your project, and stick the DLLs in there. Then you should right-click on the project, select Add Reference, browse to that new "dependencies" folder, and add a reference to the DLL that way. This is similar to the way NuGet works; it keeps DLLs in their respective folders inside the packages folder, and adds references to those DLLs.

Krummelz
  • 1,046
  • 1
  • 11
  • 23
  • Thanks, I have created a "Lib" folder and put all of the DLL there. Then I added references to them in the project. I can see them being copied across to the Lib folder under bin directory, however still can't seem to load ABC.DLL. I am confused to why the console app works but not in the web project? – user10301180 Aug 31 '18 at 21:20
  • Are these DLLs made using a newer version of the .NET framework, perhaps? – Krummelz Sep 03 '18 at 06:45
0

I finally found the issue and thanks for all the help, I had to disable shadow copying in VS (mentioned in 64 bit managed assembly with unmanaged dependencies not loading in IIS / ASP.NET MVC 4).

user10301180
  • 23
  • 2
  • 5