46

I have this dll that I created a long time ago and use to connect to the db of a specific software that I develop for. I have had no issues for well over 4 years and countless applications with this dll.

Trying to deploy my latest creation, I get the following error:

System.IO.FileNotFoundException: Could not load file or assembly '***.dll' or one of its dependencies. The specified module could not be found.

So, for every dll I ever wrote, I always made a simple forms application to test that dll just by itself. Running that simple app yielded the same error. The dll doesn't load or use anything else than: System, System.Data, System.XML. So as far as depencies of it go, I don't see anything wrong.

By the way everything works on a dev station. The problem is limited to deployment stations. .Net and the necessary redistributables, since I do everything in C++, are deployed and working.

Running FUSLOGVW.exe showed everything as working fine.

Running depends.exe said: Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

I already tried rewriting the whole thing. Which yielded the same results.

Clues anyone?

EDITS

Here is the total error message:

See the end of this message for details on invoking \"
just-in-time (JIT) debugging instead of this dialog box.\"

************** Exception Text **************\"
System.IO.FileNotFoundException: Could not load file or assembly 'connectionTo.dll' or one of its dependencies. The specified module could not be found.\"
File name: 'connectionToJobboss32.dll'\"
   at TESTConnection.Form1.button1_Click(Object sender, EventArgs e)\"
   at System.Windows.Forms.Control.OnClick(EventArgs e)\"
   at System.Windows.Forms.Button.OnClick(EventArgs e)\"
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\"
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\"
   at System.Windows.Forms.Control.WndProc(Message& m)\"
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)\"
   at System.Windows.Forms.Button.WndProc(Message& m)\"
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\"
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\"
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\"
\"



************** Loaded Assemblies **************\"
mscorlib\"
    Assembly Version: 4.0.0.0\"
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)\"
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll\"
----------------------------------------\"
TESTConnection\"
    Assembly Version: 1.0.3996.18980\"
    Win32 Version: \"
    CodeBase: file:///C:/Program%20Files%20(x86)/conn/TESTConnection.exe\"
----------------------------------------\"
System.Windows.Forms\"
    Assembly Version: 4.0.0.0\"
    Win32 Version: 4.0.30319.1 built by: RTMRel\"
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll\"
----------------------------------------\"
System.Drawing\"
    Assembly Version: 4.0.0.0\"
    Win32 Version: 4.0.30319.1 built by: RTMRel\"
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll\"
----------------------------------------\"
System\"
    Assembly Version: 4.0.0.0\"
    Win32 Version: 4.0.30319.1 built by: RTMRel\"
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll\"
----------------------------------------\"

There is no errors in the event viewer.

DominikAngerer
  • 6,354
  • 5
  • 33
  • 60
Dewm Solo
  • 671
  • 2
  • 7
  • 13

10 Answers10

41

or one of its dependencies

That's the usual problem, you cannot see a missing unmanaged DLL with Fuslogvw.exe. Best thing to do is to run SysInternals' ProcMon utility. You'll see it searching for the DLL and not find it. Profile mode in Dependency Walker can show it too.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 2
    Could you point as to what to look for in the ProcMon log or even in Dependency Walker? I honestly see nothing but Successes in both utilities. In ProcMon i do see a few 'File not found', but they are followed immediately by a search of the same file in another path and met with success. – Dewm Solo Dec 10 '10 at 19:27
  • You are looking at the right thing afaict. Disappointing, that's normally a surefire way to see it. No idea, beyond drowning in the data. You can save the trace and put it on a file sharing service if you want another set of eyes on it. – Hans Passant Dec 10 '10 at 19:35
  • 2
    Setting up the `Working Directory` field in the .NET project's settings (`Debug` tab) to the directory with all the DLLs my program depended on fixed this issue for me. – MasterMastic Mar 23 '13 at 17:16
  • 2
    You can use `Telerik Just Decompile` to show the dependencies of an assembly (exe or dll) – FindOutIslamNow Feb 08 '17 at 09:01
21

I had the same issue with a dll yesterday and all it referenced was System, System.Data, and System.Xml. Turns out the build configuration for the Platform type didn't line up. The dll was build for x86 and the program using it was "Any CPU" and since I am running a x64 machine, it ran the program as x64 and had issues with the x86 dll. I don't know if this is your issue or not, just thought that I would mention it as something else to check.

light
  • 816
  • 5
  • 16
  • Since I write in Managed C++ the "Any CPU" doesn't exist. I checked the configuration manager anyways and both, dll and app, are set for Win32. Since I am building this in 32 bits I was running it from my Program Files (x86) folder in order to avoid issues with 64bits. ...So I had been looking into this, but I didn't see anything wrong. Oh and one of the stations I am trying to deploy on is a 32 bits machine anyways. – Dewm Solo Dec 10 '10 at 16:45
  • Had similar problem. I read your answer and could not change it with VS interface. So I opened project file in text editor and change it to AnyCPU manually, and it works. Even VS interface accepted value as it should at first place. – Denis Besic Apr 15 '13 at 11:39
13

I recently hit this issue, the app would run fine on the developer machines and select others machines but not on recently installed machines. It turned out that the machines it did work on had the Visual C++ 11 Runtime installed while the freshly installed machines didn't. Adding the Visual C++ 11 Runtime redistributable to the app installer fixed the issue...

danw
  • 1,528
  • 1
  • 17
  • 17
  • 3
    Note that there are 2 versions of the Visual C++ Runtime: 32 and 64 bit. Install both of them to be sure. In my case only the 64 bit package resolved the issue. – kDar Mar 27 '14 at 08:01
6

I had the same problem. For me, it was caused by the default settings in the local IIS server on my machine. So the easy way to fix it, was to use the built in Visual Studio development server instead :)

Newer IIS versions on x64 machines have a setting that doesn't allow 32 bit applications to run by default. To enable 32 bit applications in the local IIS, select the relevant application pool in IIS manager, click "Advanced settings", and change "Enable 32-Bit Applications" from False to True

6

I ran into this recently. It turned out that the old DLL was compiled with a previous version (Visual Studio 2008) and was referencing that version of the dynamic runtime libraries. I was trying to run it on a system that only had .NET 4.0 on it and I'd never installed any dynamic runtime libraries. The solution? I recompiled the DLL to link the static runtime libraries.

Check your application error log in Event Viewer (EVENTVWR.EXE). It will give you more information on the error and will probably point you at the real cause of the problem.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • I looked at the event viewer and posted the error message I get completely. Nothing shows in the event viewer. – Dewm Solo Dec 10 '10 at 18:26
  • 1
    You say it works on dev machine but not on deployment machine. Are you deploying a debug version of the dll and you don't have the debug libraries on the deployment machine? Is there some other version of connectionTo.dll or connectionToJobboss32.dll somewhere in the search path? – Jim Mischel Dec 10 '10 at 18:34
  • I tried both debug and release versions of it. All with the same errors. I used to get the MSVCR100.dll missing error. Which is the redistributable library for applications made with MS VC++, but I do copy it along with the app now. I also replace it with MSVCR100d.dll when copying the debug version instead. – Dewm Solo Dec 10 '10 at 19:31
  • "The solution? I recompiled the DLL to link the static runtime libraries." Does that mean you recompiled the original VS 2008 DLL in VS 2010? I don't get it. Thanks – Kevin Meredith Jul 14 '11 at 18:02
2

This answer is totally unrelated to the OP's situation, and is a very unlikely scenario for anyone else too, but just in case it may help someone ...

In my case I was getting "Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0 ..." because I had disassembled and reassembled the program using ILDAsm.exe and ILAsm.exe from .Net Framework / SDK version 2. Switching to ILDAsm.exe and ILAsm.exe from .Net Framework / SDK version 4 fixed the problem.

(Strangely, even though doing what I did may seem like an obvious error, the resulting EXE file that didn't work did indicate that it targeted .Net 4 when examined with JetBrains dotPeek.)

RenniePet
  • 11,420
  • 7
  • 80
  • 106
2

I had the same issue - a .dll working all the time, then my computer crashed and afterwards I had this problem of 'could not load file or assembly ....dll'

Two possible solutions: when the computer crashed there may be some inconsistent files in

C:\Users\<yourUserName>\AppData\Local\Temp\Temporary ASP.NET Files

Deleting that folder, recompiling and the error was gone.

Once I had also to delete my packages folder (I had read that somewhere else). Allow Visual Studio / nuget to install missing packages (or manually reinstall) and afterwards everything was fine again.

outofmind
  • 1,430
  • 1
  • 20
  • 37
1

An easier way to determine what dependencies a native DLL has is to use Dependency Walker - http://www.dependencywalker.com/

I analysed the native DLL and discovered that it depended on MSVCR120.DLL and MSVCP120.DLL, both of which were not installed on my staging server in the System32 directory. I installed the C++ runtime on my staging server and the issue was resolved.

Steve Rukuts
  • 9,167
  • 3
  • 50
  • 72
  • Thanks, you saved my day. Used the tool to find out the missing libraries MSVCR100.DLL and MSVCP100.DLL, then installed [Microsoft Visual C++ 2010 Redistributable Package (x64)](http://www.microsoft.com/en-us/download/details.aspx?id=14632) and problem fixed. – Manuel Ferreiro Sep 11 '20 at 18:11
1

Had the same issue and got it resolved by making sure projects in the solution have the same configuration and platform (in my case it was Debug x64). Somehow the VIsual Studio was missing x64 for part of the projects and I edited the .sln file manually (copied the configurations and platforms from correctly built projects to the projects that were missing the settings I needed). This is what it looks like for one of the projects:

{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Debug|x64.ActiveCfg = Debug|x64
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Debug|x64.Build.0 = Debug|x64
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Release|Any CPU.Build.0 = Release|Any CPU
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Release|x64.ActiveCfg = Release|x64
{1BA29980-EE5D-4476-AFFC-0F177B6C9865}.Release|x64.Build.0 = Release|x64

But then the same error occurred for a project that had a Java file (*.jar) in the dependencies. I had to edit Environment Variables manually to create a record with this value

C:\Program Files\Java\jre1.8.0_171\bin\server

for Java's path, and put it on top of the Path items.

This fixed the issue until I updated Java on my machine. I had to edit the version number in Environment Variables to match the updated folder name.

C:\Program Files\Java\jre1.8.0_181\bin\server

Lukas G
  • 650
  • 1
  • 11
  • 33
0

1) Copy DLLs from "Externals\ffmpeg\bin" to your project's output directory (where executable stays); 2) Make sure your project is built for x86 target (runs in 32-bit mode).

Follow this thread for more