23

Inside the constructor of a Form when I am stepping through my code, a method declared in the very same form is called. Before I can step inside the method, I get a System.IO.FileNotFoundException with message "The specified module could not be found. (Exception from HRESULT: 0x8007007E)". The member method I try to enter is declared unsafe because it deals with unmanaged C++ code, but like I said I can never step into the method anyways.

Since it sounds like a DLL dependency issue, I ran Dependency Walker. Dependency walker only shows problems with MPR.DLL under SHLWAPI.DLL. The problem method is WNetRestoreConnectionA which I never call. The dependency walker FAQ suggests that this is not a problem http://dependencywalker.com/faq.html. Also, this is not a web application or anything. I am unfortunately stuck with VS2005.

What are some possible reasons for this problem to occur? Any ideas on what I could be missing or how I could debug this problem?

insipid
  • 3,238
  • 3
  • 26
  • 38

2 Answers2

17

Are you running dependency walker in profiling mode, or just static analysis? Profiling mode is what you need for this I think. But there are better solutions I believe.

You could try SysInternals ProcMon. This will allow you to see what file it is trying to load at least, and from there you might be able to figure out what the problem is.

My advice would be to fire it up, then turn off logging. Get to the point where the exception is about to happen, reenable logging, step over in the debugger so the error is generated, then disable logging again. This will leave you with only a small amount of log to deal with, otherwise it can get quite unwieldly quite quickly.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • I ran into the same issue when trying to run a Mixed mode assembly, compiled in debug, onto a newly installed machine. I did use ProcMon successfully to figure out the I needed the DEBUG version of the runtime libraries. – Vincent Hubert Jan 25 '12 at 21:28
  • 5
    I've blogged about using ProcessMonitor to trouble mixed mode assembly dependency problem here http://www.sivachandran.in/2013/03/troubleshooting-module-could-not-be.html, I hope it helps. – Sivachandran Mar 17 '13 at 16:16
  • With this approach, the trick is to look for a stream of `QueryOpen` operations for a file which result in `NAME NOT FOUND`. – John Go-Soco Sep 10 '19 at 14:41
15

The error is occurring when the .Net runtime JITs the method you're about to step into, because it couldn't find one of the types used by the method.

What exactly does the method that you can't step into do, and what types / methods does it use?

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Excellent answer, this seems to be the problem. There is a class its trying to use from a managed c++ dll it that it expects to be in the release folder but its not there. Side question, how come when I click go to definition on the class I go to this crazy directory C:\[PROFILE]\LOCALS~1\Temp\3292$[DLLNAME]$v2.0.50727\[CLASS_NAME] and the member signatures are all there. I would +1 you because this is better than what google gave me, but no rep. – insipid Jan 14 '10 at 17:57