title: C++/CLI assembly can't load imported procedure
body: <p>I have a solution in Visual Studio 2010, which contains a C++/CLI assembly. That assembly is acting as a managed/unmanaged go-between, so it both calls functions in some C# assemblies in the solution, and calls functions exported from unmanaged C++ code. The C++ code resides in a project within the same solution, but due to historical reasons that project is not built by the solution; it is compiled and linked by separate build scripts.</p>
  
  <p>Our build scripts bundle up the required files post-build to produce an installer which contains just the binaries without the project or solution files, these being rightly considered internal. </p>
  
  <p>Usually this works fine; but one particular build recently fails to run after installation with the error:</p>
  
  <pre><code>An unhandled exception of type 'System.IO.FileLoadException' occurred in Unknown Module.
  
  Additional information: A procedure imported by 'CppCliProj.dll' could not be loaded.
  </code></pre>
  
  <p><strong>Edit:</strong> Following help from HansPassant in the comments, this no longer seems to be a problem with the solution file, as before. Using loader snaps and <code>cdb</code>, I have produced the following:</p>
  
  <pre><code>Microsoft (R) Windows Debugger Version 6.2.9200.20512 X86
  Copyright (c) Microsoft Corporation. All rights reserved.
  
  CommandLine: MyApp.exe
  Symbol search path is: *** Invalid ***
  ****************************************************************************
  * Symbol loading may be unreliable without a symbol search path.           *
  * Use .symfix to have the debugger choose a symbol path.                   *
  * After setting your symbol path, use .reload to refresh symbol locations. *
  ****************************************************************************
  Executable search path is: 
  ModLoad: 00820000 00834000   MyApp.exe
  ModLoad: 774f0000 77670000   ntdll.dll
  2004:14fc @ 91201008 - LdrpInitializeProcess - INFO: Beginning execution of MyApp.exe (C:\Program Files (x86)\Path\To\MyApp.exe)
      Current directory: C:\Windows
      Search path: C:\Windows\SYSTEM32
  
  ...&lt;snip lots of output&gt;....
  
  *** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdll.dll - 
  eax=00000000 ebx=00000000 ecx=0cff0000 edx=0018dd68 esi=fffffffe edi=00000000
  eip=77590fab esp=0070f980 ebp=0070f9ac iopl=0         nv up ei pl zr na pe nc
  cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
  ntdll!LdrVerifyImageMatchesChecksum+0x96c:
  77590fab cc              int     3
  0:000&gt; .symfix
  0:000&gt; sxe clr
  0:000&gt; g
  
  ...&lt;snip&gt;...
  
  2004:14fc @ 91232426 - LdrGetDllHandleEx - ENTER: DLL name: kernel32 DLL path: NULL
  2004:14fc @ 91232426 - LdrGetDllHandleEx - INFO: Locating DLL kernel32.DLL in path C:\Program Files (x86)\Path\To;;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86\winext\arcade;C:\Program Files (x86)\Business Objects\Common\3.5\bin\NOTES\;C:\Program Files (x86)\Business Objects\Common\3.5\bin\NOTES\DATA\;C:\Training\Git\cmd;C:\Training\Ruby1.9.3\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsP
  2004:14fc @ 91232426 - LdrpFindLoadedDll - ENTER: DLL name: kernel32.DLL DLL path: C:\Program Files (x86)\Path\To;;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86\winext\arcade;C:\Program Files (x86)\Business Objects\Common\3.5\bin\NOTES\;C:\Program Files (x86)\Business Objects\Common\3.5\bin\NOTES\DATA\;C:\Training\Git\cmd;C:\Training\Ruby1.9.3\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsP
  2004:14fc @ 91232426 - LdrpFindLoadedDll - RETURN: Status: 0x00000000
  2004:14fc @ 91232426 - LdrGetDllHandleEx - RETURN: Status: 0x00000000
  2004:14fc @ 91232426 - LdrGetProcedureAddressEx - INFO: Locating procedure "GetUserPreferredUILanguages" by name
  (2004.14fc): CLR exception - code e0434352 (first chance)
  First chance exceptions are reported before any exception handling.
  This exception may be expected and handled.
  eax=0070e098 ebx=00000005 ecx=00000005 edx=00000000 esi=0070e144 edi=0095e9f0
  eip=76acc41f esp=0070e098 ebp=0070e0e8 iopl=0         nv up ei pl nz ac po nc
  cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000212
  KERNELBASE!RaiseException+0x58:
  76acc41f c9              leave
  0:000&gt; !loadby sos clr
  0:000&gt; !PrintException
  Exception object: 0298c1a0
  Exception type:   System.IO.FileLoadException
  Message:          A procedure imported by 'CppCliProj.dll' could not be loaded.
  InnerException:   &lt;none&gt;
  StackTrace (generated):
  &lt;none&gt;
  StackTraceString: &lt;none&gt;
  HResult: 8007007f
  0:000&gt; !CLRStack
  OS Thread Id: 0x14fc (0)
  Child SP IP       Call Site
  0070f24c 76acc41f [PrestubMethodFrame: 0070f24c] Radan.Radraft.Program.Main(System.String[])
  0070f488 76acc41f [GCFrame: 0070f488] 
  0:000&gt; k
  ChildEBP RetAddr  
  0070e0e8 6dc7ba10 KERNELBASE!RaiseException+0x58
  0070e178 6dd24c13 clr!RaiseTheExceptionInternalOnly+0x276
  0070e1b4 6dedd349 clr!UnwindAndContinueRethrowHelperAfterCatch+0x60
  0070e20c 6f6c7ea2 clr!CEEInfo::getCallInfo+0x162
  0070e234 6f6c858b clrjit!Compiler::eeGetCallInfo+0x39
  0070e92c 6f6c615e clrjit!Compiler::impImportBlockCode+0x2ffa
  0070e9b4 6f6c2b03 clrjit!Compiler::impImportBlock+0x21b
  0070e9cc 6f6c2b4d clrjit!Compiler::impImport+0xe8
  0070e9d8 6f6c2b7e clrjit!Compiler::fgImport+0x22
  0070e9e8 6f6c3232 clrjit!Compiler::compCompile+0x37
  0070ea24 6f6c3326 clrjit!Compiler::compCompileHelper+0x2df
  0070ea94 6f6c3459 clrjit!Compiler::compCompile+0x1ac
  0070eb70 6f6c5ddb clrjit!jitNativeCode+0x14e
  0070eb94 6dc5fe41 clrjit!CILJit::compileMethod+0x27
  0070ebfc 6dc5fecd clr!invokeCompileMethodHelper+0x65
  0070ec44 6dc5ff13 clr!invokeCompileMethod+0x31
  0070ecac 6dc5fce8 clr!CallCompileMethodWithSEHWrapper+0x2e
  0070f068 6dda6e5e clr!UnsafeJitFunction+0x3f9
  0070f148 6dda7008 clr!MethodDesc::MakeJitWorker+0x284
  0070f1b8 6dc4b100 clr!MethodDesc::DoPrestub+0x45d
  0070f21c 00a80842 clr!PreStubWorker+0x12c
  WARNING: Frame IP not in any known module. Following frames may be wrong.
  0070f234 6dc121bb 0xa80842
  0070f264 6dc4a7aa clr!CallDescrWorker+0x33
  0070f2e0 6dc4a94c clr!CallDescrWorkerWithHandler+0x8e
  0070f420 6dc4a981 clr!MethodDesc::CallDescr+0x194
  0070f43c 6dc4a9a1 clr!MethodDesc::CallTargetWorker+0x21
  0070f454 6dd99e02 clr!MethodDescCallSite::Call+0x1c
  0070f5b8 6dd99f10 clr!ClassLoader::RunMain+0x24c
  0070f820 6dd99d24 clr!Assembly::ExecuteMainMethod+0xc1
  0070fd04 6dd9a119 clr!SystemDomain::ExecuteMainMethod+0x4ec
  0070fd58 6dd9a01a clr!ExecuteEXE+0x58
  0070fda4 6dd4cb38 clr!_CorExeMainInternal+0x19f
  0070fddc 6e2855ab clr!_CorExeMain+0x4e
  0070fde8 735e7f16 mscoreei!_CorExeMain+0x38
  0070fdf8 735e4de3 MSCOREE!ShellShim__CorExeMain+0x99
  0070fe00 769633aa MSCOREE!_CorExeMain_Exported+0x8
  0070fe0c 77529ef2 KERNEL32!BaseThreadInitThunk+0xe
  0070fe4c 77529ec5 ntdll!RtlInitializeExceptionChain+0x63
  0070fe64 00000000 ntdll!RtlInitializeExceptionChain+0x36
  </code></pre>
  
  <p>I am running a 32-bit application on Windows 7 Professional 64-bit.</p>