title: DllImport generates System.DllNotFoundException
body: <p>I’m having some difficulties while trying to consume an unmanaged-code <code>dll</code> from my application (written in C# framework 4.0).
  I’m using the <code>dll</code> import as follows </p>
  
  <pre><code>[DllImport(@"C:\MGW_SDK.dll", EntryPoint = "fInicializaSDK")]
  public static extern int fInicializaSDK();
  </code></pre>
  
  <p>The weird thing is that when called from my development environment (Windows XP) it works just fine, but when on the production server (Windows7) it generates the following exception:</p>
  
  <blockquote>
    <p><code>System.DllNotFoundException</code>: Unable to load DLL <code>' C:\MGW_SDK.dll'</code>: The specified module could not be found. (Exception from HRESULT: 0x8007007E)     at <code>Comtpaq.AdminPack.SDKWrapper.fInicializaSDK()</code>     at <code>Comtpaq.AdminPack.AdminPaqRepository.InitializeSDK()</code> in <code>C:\Work\AgroIn\AdminPaqRepository.cs</code>:line 30</p>
  </blockquote>
  
  <p>I already ran <a href="http://www.dependencywalker.com/" rel="nofollow">Dependency Walker</a>, which shows the following dependency as conflicted: <code>C:\windows\system32\SHLWAPI.DLL</code></p>
  
  <p>I already tried copying that <code>dll</code> to my deployment directory</p>
  
  <p>The <code>MGW_SDK.dll</code> is on <code>c:\</code> (as the path says)</p>
  
  <p>I already installed C Runtime Library</p>
  
  <p>I also noticed some interesting stuff: on the exception, the development path is showing <code>C:\Work\AgroIn\AdminPaqRepository.cs:line 30</code></p>
  
  <p>What else could be the problem here?</p>
  
  <h3>Edit</h3>
  
  <p>I built a small console application with just one of the <code>extern</code>/<code>dllimport</code> methods that I use from <code>MGW_SDK.dll</code> and ran it with no problem (no <code>DllNotFoundException</code> whatsoever), so this seems to be related to the application that I'm building (a WCF Service).  This service is hosted on the WAS, but I'm still unable to find the issue.</p>