title: Trouble displaying C# stack trace in WinDbg
body: <p>I have a handle leak in a C# program. I'm trying to diagnose it using WinDbg using !htrace, roughly as presented in <a href="https://stackoverflow.com/a/7617994/1496914">this answer</a>, but when I run !htrace -diff in WinDbg I'm presented with stack traces that don't show the names of my C# functions (or even my .net assembly).</p>
  
  <p>I created a small test program to illustrate my difficulty. This program does nothing except "leak" handles.</p>
  
  <pre><code>class Program
  {
      static List&lt;Semaphore&gt; handles = new List&lt;Semaphore&gt;();
  
      static void Main(string[] args)
      {
          while (true)
          {
              Fun1();
              Thread.Sleep(100);
          }
      }
  
      static void Fun1()
      {
          handles.Add(new Semaphore(0, 10));            
      }
  }
  </code></pre>
  
  <p>I compiled the assembly, and then in WinDbg I go "File" -> "Open Executable" and select my program (D:\Projects\Sandpit\bin\Debug\Sandpit.exe). I continue program execution, break it, and run "!htrace -enable", then continue for a bit longer, and then break and run "!htrace -diff". This is what I get:</p>
  
  <pre><code>0:004&gt; !htrace -enable
  Handle tracing enabled.
  Handle tracing information snapshot successfully taken.
  0:004&gt; g
  (1bd4.1c80): Break instruction exception - code 80000003 (first chance)
  eax=7ffda000 ebx=00000000 ecx=00000000 edx=77b2f17d esi=00000000 edi=00000000
  eip=77ac410c esp=0403fc20 ebp=0403fc4c 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!DbgBreakPoint:
  77ac410c cc              int     3
  0:004&gt; !htrace -diff
  Handle tracing information snapshot successfully taken.
  0xd new stack traces since the previous snapshot.
  Ignoring handles that were already closed...
  Outstanding handles opened since the previous snapshot:
  --------------------------------------
  Handle = 0x00000250 - OPEN
  Thread ID = 0x00001b58, Process ID = 0x00001bd4
  
  0x77ad5704: ntdll!ZwCreateSemaphore+0x0000000c
  0x75dcdcf9: KERNELBASE!CreateSemaphoreExW+0x0000005e
  0x75f5e359: KERNEL32!CreateSemaphoreW+0x0000001d
  *** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\System\13c079cdc1f4f4cb2f8f1b66c8642faa\System.ni.dll
  0x65d7e805: System_ni+0x0020e805
  0x65d47843: System_ni+0x001d7843
  0x65d477ef: System_ni+0x001d77ef
  0x004700c9: +0x004700c9
  0x67d73dd2: clr!CallDescrWorkerInternal+0x00000034
  0x67d9cf6d: clr!CallDescrWorkerWithHandler+0x0000006b
  0x67d9d267: clr!MethodDescCallSite::CallTargetWorker+0x00000152
  0x67eb10e0: clr!RunMain+0x000001aa
  0x67eb1200: clr!Assembly::ExecuteMainMethod+0x00000124
  --------------------------------------
  Handle = 0x0000024c - OPEN
  Thread ID = 0x00001b58, Process ID = 0x00001bd4
  
  0x77ad5704: ntdll!ZwCreateSemaphore+0x0000000c
  0x75dcdcf9: KERNELBASE!CreateSemaphoreExW+0x0000005e
  0x75f5e359: KERNEL32!CreateSemaphoreW+0x0000001d
  0x65d7e805: System_ni+0x0020e805
  0x65d47843: System_ni+0x001d7843
  0x65d477ef: System_ni+0x001d77ef
  0x004700c9: +0x004700c9
  0x67d73dd2: clr!CallDescrWorkerInternal+0x00000034
  0x67d9cf6d: clr!CallDescrWorkerWithHandler+0x0000006b
  0x67d9d267: clr!MethodDescCallSite::CallTargetWorker+0x00000152
  0x67eb10e0: clr!RunMain+0x000001aa
  0x67eb1200: clr!Assembly::ExecuteMainMethod+0x00000124
  ...
  --------------------------------------
  Displayed 0xd stack traces for outstanding handles opened since the previous snapshot.
  </code></pre>
  
  <p>As you can see, the stack trace is missing my C# function names "Main" and "Fun1". I believe "System_ni+0x..." frames may be my function frames, but I don't know. My question is, how do I get WinDbg to display function names for my C# functions in the stack trace?</p>
  
  <p>Extra information:
  My WinDbg symbol search path is</p>
  
  <blockquote>
    <p>SRV<em>C:/symbols</em><a href="http://msdl.microsoft.com/download/symbols;D" rel="nofollow noreferrer">http://msdl.microsoft.com/download/symbols;D</a>:\Projects\Sandpit\bin\Debug;srv*</p>
  </blockquote>
  
  <p>I don't get any errors when I open the executable in WinDbg. There is a file called "Sandpit.pdb" in the output directory ("D:\Projects\Sandpit\bin\Debug"). The project is built locally so the pdb file should match the exe. I downloaded WinDbg <a href="http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx" rel="nofollow noreferrer">from here</a>. I have "Enable native code debugging" checked in the project settings in Visual Studio.</p>