An unexplainable DllNotFoundException :(

G

Guest

I'm having a very odd problem. I have a basic C# form app that pInvokes into
a C++ dll. When I build my C++ dll and C# app in Release mode, the C# app can
load the dll and call into it just fine.

However if I build the solution in Debug mode, the C# app throws a
DllNotFoundException. I've double checked and the C++ debug version of the
dll is being properly copied into the C# app's bin/debug folder, so its
actually there.

Why is it able to load the release version and not the debug version?:mad:
 
R

Richard Grimes

dxben said:
I'm having a very odd problem. I have a basic C# form app that
pInvokes into a C++ dll. When I build my C++ dll and C# app in
Release mode, the C# app can load the dll and call into it just fine.

However if I build the solution in Debug mode, the C# app throws a
DllNotFoundException. I've double checked and the C++ debug version
of the dll is being properly copied into the C# app's bin/debug
folder, so its actually there.

Why is it able to load the release version and not the debug
version?:mad:

dumpbin /imports (or /dependents in VS2005) to see the list of the DLLs
that the C++ DLL loads. Make sure that those DLLs are in the path, or in
the local folder. I suspect that the debug version of the CRT is not
available.

Richard
 
G

Guest

I've tried to copy it into every folder in the hierarchy from where the c#
project file is on down to the debug folder and everything in between. Its
bizarre. I have even used Filemon to see what's happening and it appears that
its finding the file and trying and even succeeding at opening it, but then
it throws. I don't get it.
 
G

Guest

Richard,

Thanks for that suggestion. I haven't tried it yet but it would make sense
as the C++ dll is built against the debug DLL version of the CRT. If that's
it, where would that be on the system, isn't that installed by VisualStudio?
What is the filename for the debug CRT dll, I'll try to search it on my
system.

Thanks,

Benjamin
 
V

Vadym Stetsyak

If it is not the CRT, I'd recommend you to check the dependency list of the
dll. You can use Dependency Walker.

Try to search in your Visual Studio folder - depends.exe
 
G

Guest

Ok I figured out that the filename for the debug CRT dll is MSVCRTD.DLL ,
however I don't see any versions of this file that are based on the CRT that
shipped with VS2K5, I have plenty of old versions of this file on my system
that shipped with various apps. Do I need to download the platform sdk to be
able to have this? I would think not.
 
G

Guest

Ok I ran depends on my dll and it seems that when I run depends it shows that
it can't find MSJAVA.dll. I don't know why my dll would need to depend on
that and what's odd is that the release version of my dll also shows that it
can't find MSJAVA.dll, so if that's the reason, why is the release version
loading and not my debug version?

I've done a search on my box for MSJAVA.dll and its nowhere to be found. How
can I either remove the dependency from my dll or get it installed?
 
G

Guest

Ok, I think I solved it, I placed MSVCP80D.dll and MSVCR80D.dll in my /debug
folder and it now runs, but gives me a new error:

Loader Lock was detected:
Attempting managed execution inside OS Loader lock. Do not attempt to run
managed code inside a DllMain or image initialization function since doing so
can cause the application to hang.
 
R

Richard Grimes

dxben said:
my dll also shows that it can't find MSJAVA.dll, so if that's the
reason, why is the release version loading and not my debug version?

I don't know.
I've done a search on my box for MSJAVA.dll and its nowhere to be
found. How can I either remove the dependency from my dll or get it
installed?

Are you compiling the C++ DLL? If so, check the depends list against the
import libraries used on the linker line, to determine which import
library brings in the DLL. Then remove that import library and re-link
and see what code in your project uses that library. I suspect you'll
get a lot of linker errors, in which case, note the functions where the
errors occur, reinstate the import library and one by open comment out
the code in those functions. After each build use depends to see if the
dependency on msjava is removed. At that point, you can pin point where
the problem lies.

Richard
 
R

Richard Grimes

dxben said:
Ok, I think I solved it, I placed MSVCP80D.dll and MSVCR80D.dll in my
/debug folder and it now runs, but gives me a new error:

Loader Lock was detected:
Attempting managed execution inside OS Loader lock. Do not attempt to
run managed code inside a DllMain or image initialization function
since doing so can cause the application to hang.

Oops. This is the managed C++ mixed mode loader bug. You have to
initialize the DLL outside of DllMain. Here's the problem:

http://msdn.microsoft.com/library/d...stechart/html/vcconMixedDLLLoadingProblem.asp

Here's the suggested workaround:

http://msdn.microsoft.com/library/d...tsfrompureintermediatelanguagetomixedmode.asp

don't you just love those long pages names?

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top