DllNotFoundException- path problems

Hello all,
I've got a project that pinvokes an unmanaged DLL and everything runs smoothly with it.
The problem begins when I publish the project and install it on a different computer- I get the DllNotFoundException when it's being called, and the oddest thing is that the message says the dll wasn't found on the project's bin\debug path. The problem is that I wish to have the dll on the application startup path, but cannot use Application.StartupPath within the DllImport Attribute, since it takes only consts. Does anyone know why does the application search for the dll in the bin\debug folder Is there anyway to change this (I've tried adding the app startup path to the environment path, didn't work) Or better yet, is there a way of using the Application.StartupPath when using the DllImport Attribute



Answer this question

DllNotFoundException- path problems

  • nsam

    Hello mattias, thanks for taking your time :)
    the attribute is very simple:
    [DllImport("MyDll.dll", EntryPoint = "MyMethod")]


  • DenisCote

    Hello Mattias,
    I came across this sample of yours, suggesting to use System.Reflection.Emit in order to set dll path at runtime. Could this be what I was after


  • Wojtek

    What does your DllImport attribute look like

  • Chandrakanttt

    When I click profile, the application isn't started, the log view delivers a few lines (the regular 'Started' and 'Loaded') and then I get the line:
    00:00:00.235: Exited "c:\Application path\MyApp.EXE" (process 0x20C) with code -1073740791 (0xC0000409) by thread 1.
    and the profiling process is stopped. This actually happens with the published application as well as with the .exe file in the bin\Debug folder of the (unpublished) project.


  • AussieNoobie

    Nah. Use the Profile menu option of DependencyWalker to see what DLL it is trying to load.


  • neotom

    Sorry guys for flooding this thread here...
    nobugz- I've found out the walker wasn't profiling actually since there were a couple of problems- on dll missing (which i've solved by removing IE7 from my machine), and now there's MPR.DLL that is in red and the message says:
    Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
    The walker still doesn't profile- any ideas


  • Andres Aguiar

    The DLL you're P/Invoking might itself need other DLLs that are not present on the target system. You'll get the same exception as though the DLL wasn't present. Use DependencyWalker if you have trouble figuring out what those DLLs might be.


  • Davids Learning

    nobugz wrote:
    The DLL you're P/Invoking might itself need other DLLs that are not present on the target system. You'll get the same exception as though the DLL wasn't present. Use DependencyWalker if you have trouble figuring out what those DLLs might be.


    Indeed, this dll needs another dll, but I made sure before testing that they are both present in the same folder, so I honestly don't think the problem is there. So, in fact the app was supposed to look for this dll in the application exe folder Could it be that it has something to do with the signing or the use deploy file extension I've been trying to work around this all day yesterday, and still I haven't the slightest idea...


  • Lostlogic

    Is it possible this is due to the fact these dlls are situated in the bin\Debug folder of a project that is added as a reference to the main project in this solution (sorry, but this is doing my head in!)


  • ShaneShowers

    That's normal, MPR.dll is a optional delay-loaded DLL that's always missing. What happens when you click Profile


  • Joe G

    Well, I run the walker and then the profiler and then I run my app but it doesn't register anything further than 00:00:00.110: Exited "c:\path\MYAPP.EXE" (process 0x7B4) with code -1073740791 (0xC0000409) by thread 1.
    I play about with the app so that the missing dlls will be called, still nothing in the Walker's log view... Arrrrggghhhh :p


  • DllNotFoundException- path problems