23

I am building a dll, which references a second dll. I have added the second dll as a reference in the first dll's project by going to Properties > Common Properties > Framework and References > Add New Reference > Browse

I compiled the second dll from a third party's source code. Both projects are C++/CLI. Whenever my main application tries to call a function in the first dll which contains a call to the second dll, I get the following error:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.

Additional information: Could not load file or assembly 'NBIS, Version=1.0.5156.29834, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

I have a copy of the second dll in the same directory as my main exe, and I've even tried keeping a copy next to the first dll as well, to no avail.

The second dll references several static libraries, but the only Assembly References it contains are

System

System.Data

System.Drawing

System.XML

All of which I have added as assembly references in the first dll.

What can I do to get my application to find and load the second dll?

duggulous
  • 2,427
  • 3
  • 23
  • 40
  • 3
    "or one of its dependencies" – Hans Passant Feb 13 '14 at 19:58
  • @HansPassant Since the only dynamic libraries referenced are the ones I've listed, wouldn't that suggest that it's not due to a dependency? – duggulous Feb 13 '14 at 20:35
  • That assumes that you know what the dependencies are for nbis.dll. You don't know. The vendor or author knows. – Hans Passant Feb 13 '14 at 21:01
  • @HansPassant I compiled nbis.dll from the author's source. The assemblies listed in the nbis project properties were: System, System.Data, System.Drawing, System.XML. All other dependencies were static libraries. Is there somewhere else dependencies might be hiding? – duggulous Feb 13 '14 at 21:14
  • 3
    Use SysInternals' Process Monitor. You'll see your program searching for the DLL and not finding it. – Hans Passant Feb 13 '14 at 21:15
  • @HansPassant Ah, nice, thanks for pointing me toward that valuable tool! The main app was looking in the wrong place for the second dll. Using ProcessMonitor allowed me to see where it was searching. Problem solved. If you want to resubmit your last comment as an answer, I'll mark it correct. – duggulous Feb 13 '14 at 22:42
  • Possible duplicate of [Could not load file or assembly or one of its dependencies](https://stackoverflow.com/questions/4469929/could-not-load-file-or-assembly-or-one-of-its-dependencies) – StayOnTarget Dec 19 '18 at 22:02
  • You also use dependency walker (depends.exe) from Microsoft and observe what dependencies the DLL has. – Su Llewellyn Apr 10 '23 at 16:40

5 Answers5

36

As pointed out in the comments, SysInternals' Process Monitor is a valuable tool to diagnose DLL resolution problems. Tells you when a 3rd party DLL has a dependency you don't know about, also tells you when Windows is looking in the wrong corner of your hard drive for the file or finds the wrong one.

Loader snaps is the built-in diagnostic tool for Windows. But Process Monitor is far more convenient.

It does generate rather a lot of information, start from the bottom of the trace or enable tracing at just the right time. You often need to use its filtering tools to turn the firehose in a relevant trickle. Worth the hour of your time to figure it out, this tool belongs on any programmer's black belt.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
5

Right click on the project you created the dll and the new referencing project, then select properties. Under Application, check the target framework and verify that both have the same framework, some dll projects tend to select 'client profile' version of the framework by default, which tend to give the error you are having now..

Let me know if this is not the issue..

L.W.C. Nirosh
  • 332
  • 1
  • 9
  • 2
    Both projects target .NET v4.5 as you can see in these images: [dll1](http://ubuntuone.com/17dVhPyuIGaTtSBJla0xel) [dll2](http://ubuntuone.com/0YHXtKOvXuKnzwy8w4fbez) – duggulous Feb 13 '14 at 16:24
3

My PowerShell ISE wasn't running as an Administrator. This seemed to be the problem for me.

PeterX
  • 2,713
  • 3
  • 32
  • 42
0

Please Change your application pool setting.
Keep the steps:

  1. IIS manager open
  2. Click 'Application pools' (Application pools list)
  3. Select your application pool
  4. Right click your application pool and select 'Advanced settings '
  5. Change 'Enable 32-bit application' from false to true. (When you create application pool Enable 32-bit application default assign false)
skypjack
  • 49,335
  • 19
  • 95
  • 187
Vijaykumar
  • 11
  • 4
0

For the alert error ("The system cannot find the file specified.")

  1. Right click on [Solution Program name] then select Build Dependencies> & left click on Build Customizations... then true-checkbox {MASM} then click OK button.

  2. Right click on [Solution Program name] then left click on Properties, left click on "Linker" form "Linker" choose "Debugging" left click on "Debugging" from "Debugging" choose "Debugging Assembly" & convert the value of "Debugging Assembly" to "Yes (/ASSEMBLYDEBUG)", form "Linker" choose "System" left click on "System" from "System" choose "SubSystem" & convert the value of "SubSystem" to "Windows (/SUBSYSTEM:WINDOWS)",, left click on OK button.

  3. Right click on [Solution Program name] then Add> new item, "C++ File(.cpp)" change the name or rename "new item" to "Main.asm" then left click on Add button, Right click on [Main.asm] then left click on Properties select "General" from "General" choose "Item Type" and convert the value of "Item Type" to "Microsoft Macro Assembler" press left click on OK button, then then then Write your assembly code in "Main.asm" file then [[[Debug]]] it using 'step over === F10' from "Debug" tool-bar on top-screen program, all this about how to using assembly code in "Visual Studio 2017".

slfan
  • 8,950
  • 115
  • 65
  • 78