title: Using WinDBG to Identify Defective Function in C# program written in VS2012
body: <p>I get the following errors when using Windbg to debug a C# application written in VS2012 on another machine (it is running on the development machine, but not on a different test machine)</p>
  
  <pre><code>ModLoad: 00fd0000 01146000   ECM.exe
  ModLoad: 77400000 7753c000   ntdll.dll
  ModLoad: 6fca0000 6fcea000   C:\Windows\SYSTEM32\MSCOREE.DLL
  ModLoad: 76240000 76314000   C:\Windows\system32\KERNEL32.dll
  ModLoad: 756c0000 7570b000   C:\Windows\system32\KERNELBASE.dll
  (470.fb8): Break instruction exception - code 80000003 (first chance)
  eax=00000000 ebx=00000000 ecx=0015f588 edx=774470f4 esi=fffffffe edi=00000000
  eip=774a05a6 esp=0015f5a4 ebp=0015f5d0 iopl=0         nv up ei pl zr na pe nc
  cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
  ntdll!LdrpDoDebuggerBreak+0x2c:
  774a05a6 cc              int     3
  </code></pre>
  
  <p>After pressing g to continu I get</p>
  
  <pre><code>ModLoad: 759d0000 75a70000   C:\Windows\system32\ADVAPI32.dll
  ModLoad: 760f0000 7619c000   C:\Windows\system32\msvcrt.dll
  ModLoad: 775e0000 775f9000   C:\Windows\SYSTEM32\sechost.dll
  ModLoad: 76540000 765e2000   C:\Windows\system32\RPCRT4.dll
  ModLoad: 6e3e0000 6e45b000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll
  ModLoad: 75dc0000 75e17000   C:\Windows\system32\SHLWAPI.dll
  ModLoad: 77590000 775de000   C:\Windows\system32\GDI32.dll
  ModLoad: 75cf0000 75db9000   C:\Windows\system32\USER32.dll
  ModLoad: 75f60000 75f6a000   C:\Windows\system32\LPK.dll
  ModLoad: 75800000 7589d000   C:\Windows\system32\USP10.dll
  ModLoad: 75f70000 75f8f000   C:\Windows\system32\IMM32.DLL
  ModLoad: 75e80000 75f4c000   C:\Windows\system32\MSCTF.dll
  ModLoad: 69670000 69d0b000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
  ModLoad: 6b1f0000 6b2c3000   C:\Windows\system32\MSVCR110_CLR0400.dll
  (470.fb8): Unknown exception - code 04242420 (first chance)
  ModLoad: 68640000 6966e000   C:\Windows\assembly\NativeImages_v4.0.30319_32    \mscorlib\ce5f61c5754789df97be8dc991c47d07\mscorlib.ni.dll
  ModLoad: 75f90000 760ec000   C:\Windows\system32\ole32.dll
  ModLoad: 75350000 7535c000   C:\Windows\system32\CRYPTBASE.dll
  ModLoad: 74200000 74240000   C:\Windows\system32\uxtheme.dll
  ModLoad: 711d0000 71228000   C:\Program Files\Common Files\microsoft shared\ink\tiptsf.dll
  ModLoad: 75c10000 75c9f000   C:\Windows\system32\OLEAUT32.dll
  ModLoad: 74910000 74919000   C:\Windows\system32\version.dll
  ModLoad: 6c810000 6c88d000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll
  ModLoad: 6bb80000 6bbd2000   DCLib.dll
  ModLoad: 003f0000 00442000   DCLib.dll
  ModLoad: 74e70000 74e86000   C:\Windows\system32\CRYPTSP.dll
  ModLoad: 74c10000 74c4b000   C:\Windows\system32\rsaenh.dll
  ModLoad: 753f0000 753fe000   C:\Windows\system32\RpcRtRemote.dll
  ModLoad: 590b0000 59a4a000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System\ff26cc03e6d57d8abd13b990332e67c6\System.ni.dll
  ModLoad: 6ba90000 6bb80000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Configuration\bbc48ec4245e502ae19b0601d3799c9e\System.Configuration.ni.dll
  ModLoad: 6a210000 6a3a4000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Drawing\5cd2aee5e7c07227c694d89219688ab3\System.Drawing.ni.dll
  ModLoad: 566f0000 5733f000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\f4f6ee0df2aa4189bf36e6335cb92761\System.Windows.Forms.ni.dll
  ModLoad: 6cc50000 6cc62000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll
  ModLoad: 67ee0000 68631000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Xml\bada32953bb6b16a53d653eae23d78dc\System.Xml.ni.dll
  (470.fb8): C++ EH exception - code e06d7363 (first chance)
  (470.fb8): C++ EH exception - code e06d7363 (first chance)
  (470.fb8): C++ EH exception - code e06d7363 (first chance)
  (470.fb8): CLR exception - code e0434352 (first chance)
  (470.fb8): C++ EH exception - code e06d7363 (first chance)
  (470.fb8): CLR exception - code e0434352 (first chance)
  (470.fb8): CLR exception - code e0434352 (first chance)
  ModLoad: 6a130000 6a204000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\diasymreader.dll
  (470.fb8): CLR exception - code e0434352 (!!! second chance !!!)
  eax=0015e804 ebx=00000005 ecx=00000005 edx=00000000 esi=0015e8c4 edi=00000001
  eip=756c812f esp=0015e804 ebp=0015e854 iopl=0         nv up ei pl nz ac po nc
  cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000212
  KERNELBASE!RaiseException+0x58:
  756c812f c9              leave
  </code></pre>
  
  <p>I've entered .loadby sos clr and !pe and that gives the following</p>
  
  <pre><code>c0000005 Exception in C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.pe debugger extension.
    PC: 6b3d42c3  VA: 00000000  R/W: 0  Parameter: 0001007f
  </code></pre>
  
  <p>Googling that I can only find <a href="http://social.msdn.microsoft.com/Forums/en-US/6a0af34b-ce48-4dcb-8b87-ed80f9477a86/windbg-clrjitdll-exception?forum=architecturegeneral" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/6a0af34b-ce48-4dcb-8b87-ed80f9477a86/windbg-clrjitdll-exception?forum=architecturegeneral</a> which is unanswered. Googling to get further I found "!dumpheap -type Exception" which gives</p>
  
  <pre><code>688391fc        1           12 System.Text.DecoderExceptionFallback
  688391b8        1           12 System.Text.EncoderExceptionFallback
  68842570        1           84 System.ExecutionEngineException
  6884252c        1           84 System.StackOverflowException
  688424e8        1           84 System.OutOfMemoryException
  68842394        1           84 System.Exception
  6883c644        1           96 System.IO.FileNotFoundException
  688425b4        2          168 System.Threading.ThreadAbortException
  6884b940        2          176 System.TypeInitializationException
  </code></pre>
  
  <p>Which brings me back to the TypeInitializationException, I read somewhere else already that loading ExecutionEngineException, StackOverflowException and OutOfMemoryException always happens so they can be thrown when they occur instead of the need to create them at that point.</p>
  
  <p>Remote debugging and checking all Thrown exceptions finally gives this line of information:</p>
  
  <pre><code> The assembly with display name 'DCLib' failed to load in the 'Load' binding context of the AppDomain with ID 1. The cause of the failure was: System.BadImageFormatException: Could not load file or assembly 'DCLib, Version=1.0.0.3, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
  </code></pre>
  
  <p>I found out the BadImageFormatException had to do with 64 bit software being called on a 32 bit system so I commentend out code using Wow64DisableWow64FsRedirection and such that I needed for a component to work on my development machine. Then the program actually remotely starts when inside the VS debugger but only after clicking continue a couple of times, and as the program still doesn't start on the test machine itself at least one of the messages I click away needs to be resolved as well  ...</p>
  
  <p>The second problem was also a TypeInitializationException, it searched for some SQL Server 2012 class or dll while the SQL Server installed on the test machine was SQL Server 2008. After I installed SQL Server 2012 everything worked. So handy that a .Net application not just tells in a log files or something what it searches for and cannot find, but rather just crashes and tells nothing and it's needed to do a remote debug session to find out.</p>