title: Symbols for ngen-ed assemblies are not loaded
body: <p>I am trying to decode the following call stack line from procmon:</p>
  
  <pre><code>29  System.Management.Automation.ni.dll System.Management.Automation.ni.dll + 0x897a0a  0x7fee2ae7a0a   C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a86698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll
  </code></pre>
  
  <p>As you can see there is an NGEN-ed assembly in it: <strong>System.Management.Automation.ni.dll</strong>. I created a pdb file for it with <strong>ngen createpdb</strong>:</p>
  
  <pre><code>PS&gt; ngen createpdb c:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a86698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll c:\symbols\ngen
  
  Successfully generated PDB for native assembly 'c:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a8698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll'.
  PDB generated in directory c:\symbols\ngen\System.Management.Automation.ni.pdb a86698074f28597f1fc5ceabfed6fed61\
  </code></pre>
  
  <p>My Symbol path in the <strong>_NT_SYMBOL_PATH</strong> variable is:</p>
  
  <pre><code>SRV*C:\symbols\ngen*;SRV*C:\symbols\dbg*http://referencesource.microsoft.com/symbols;SRV*C:\symbols\dbg*http://msdl.microsoft
  </code></pre>
  
  <p>.com/download/symbols</p>
  
  <p>But I can still see that the newly generated symbol file is not loaded for the assembly:</p>
  
  <pre><code>PS a86698074f28597f1fc5ceabfed6fed6&gt; dbh -n .\System.Management.Automation.ni.dll
  verbose mode on.
  DBGHELP: No header for .\System.Management.Automation.ni.dll.  Searching for image on disk
  DBGHELP: C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a86698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll - OK
  SYMSRV:  C:\symbols\ngen\System.Management.Automation.pdb\6B8B8F14D0564CB893B6E84B43CAE67B1\System.Management.Automation.pdb - file not found
  SYMSRV:  C:\tools\diag\Debugging Tools for Windows\x64\sym\System.Management.Automation.pdb\6B8B8F14D0564CB893B6E84B43CAE67B1\System.Management.Automation.pdb - file not found
  SYMSRV:  C:\symbols\ngen\System.Management.Automation.pdb\6B8B8F14D0564CB893B6E84B43CAE67B1\System.Management.Automation.pdb not found
  SYMSRV:  C:\tools\diag\Debugging Tools for Windows\x64\sym\System.Management.Automation.pdb\6B8B8F14D0564CB893B6E84B43CAE67B1\System.Management.Automation.pdb not found
  DBGHELP: System.Management.Automation.ni - public symbols
          C:\symbols\dbg\System.Management.Automation.pdb\6B8B8F14D0564CB893B6E84B43CAE67B1\System.Management.Automation.pdb
  </code></pre>
  
  <p>I've checked the debug header in the .dll file and it has two entries:</p>
  
  <pre><code>PS&gt; dumpbin /headers .\System.Management.Automation.ni.dll
  ...
    Debug Directories
          Time Type        Size      RVA  Pointer
      -------- ------- -------- -------- --------
      56BEFBC1 cv           11C 01F200A4  1F1E8A4    Format: RSDS, {A8669807-4F28-597F-1FC5-CEABFED6FED6}, 1, System.Management.Automation.ni.pdb
      56BEFBC1 cv            39 01F201C0  1F1E9C0    Format: RSDS, {6B8B8F14-D056-4CB8-93B6-E84B43CAE67B}, 1, System.Management.Automation.pdb
  ...
  </code></pre>
  
  <p>The <strong>A8669807-4F28-597F-1FC5-CEABFED6FED6</strong> entry is first, but seems that is never used by dbh (or actually dbghelp), and it is only looking for the <strong>6B8B8F14-D056-4CB8-93B6-E84B43CAE67B</strong>. I tried setting the symbols path only to the C:\symbols\ngen, but it didn't help - the symbol file was still not found. </p>
  
  <p>My dbghelp version is: 10.0.10240.16399</p>
  
  <p>Can someone point me what I'm doing wrong here?</p>
  
  <h3>EDIT 1:</h3>
  
  <p>Seems that the dbh verbose output is pretty consistent with what procmon is showing:</p>
  
  <p><a href="https://i.stack.imgur.com/XNgKx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XNgKx.png" alt="Screenshot of Process Monitor"></a></p>
  
  <h3>EDIT 2 (to Hans answer)</h3>
  
  <p>My application is actually a Powershell script. I listed .NET modules for powershell.exe in Process Hacker and found that it's using System.Management.Automation.dll version 3.0.0:</p>
  
  <p><a href="https://i.stack.imgur.com/vdGfZ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vdGfZ.png" alt="Screenshot of loaded assemblies"></a> </p>
  
  <p>I suppose that the original assembly is located in GAC: c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll</p>
  
  <p>which apparently was created for .NET 4.0:</p>
  
  <pre><code>PS temp&gt; corflags c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
  Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  4.6.1055.0
  Copyright (c) Microsoft Corporation.  All rights reserved.
  Version   : v4.0.30319
  CLR Header: 2.5
  PE        : PE32
  CorFlags  : 0x9
  ILONLY    : 1
  32BITREQ  : 0
  32BITPREF : 0
  Signed    : 1
  </code></pre>
  
  <p>Now, I've also looked for any other System.Management.Automation assemblies in the NativeImages folder, but there is only 1 for .NET 4.0 64-bit:</p>
  
  <p><a href="https://i.stack.imgur.com/CCEg9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CCEg9.png" alt="Screenshot"></a></p>
  
  <p>The .aux header also seems to mention only the 3.0.0 version. Notice also that the .ni file has TWO PDB files referenced in the Debug header. One of them is the one I want.</p>
  
  <h3>EDIT 3 (fuslogvw)</h3>
  
  <p>As advised by Hans I enabled the Fusion log for Native Images. Below is the snippet showing the path from which the Automation assembly is loaded:</p>
  
  <pre><code>... Pre-bind state information ...
  LOG: DisplayName = System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
   (Fully-specified)
  LOG: Appbase = file:///C:/Windows/System32/WindowsPowershell/v1.0/
  LOG: Initial PrivatePath = NULL
  LOG: Dynamic Base = NULL
  LOG: Cache Base = NULL
  LOG: AppName = powershell.exe
  Calling assembly : Microsoft.PowerShell.ConsoleHost, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
  ...
  LOG: Start validating all the dependencies.
  LOG: [Level 1]Start validating native image dependency mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  LOG: [Level 1]Start validating native image dependency System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  LOG: [Level 1]Start validating IL dependency Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
  LOG: [Level 1]Start validating native image dependency System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  LOG: [Level 1]Start validating IL dependency System.Configuration.Install, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
  LOG: [Level 1]Start validating IL dependency System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  LOG: [Level 1]Start validating IL dependency System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  LOG: [Level 1]Start validating IL dependency Microsoft.Management.Infrastructure.Native, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
  LOG: [Level 1]Start validating IL dependency System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
  LOG: [Level 1]Start validating IL dependency System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
  LOG: [Level 1]Start validating IL dependency System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
  LOG: [Level 1]Start validating IL dependency System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  LOG: [Level 1]Start validating IL dependency Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
  LOG: [Level 1]Start validating IL dependency System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
  LOG: [Level 1]Start validating IL dependency System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  LOG: [Level 1]Start validating IL dependency System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  LOG: [Level 1]Start validating IL dependency System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
  LOG: [Level 1]Start validating IL dependency SMDiagnostics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  Native image has correct version information.
  LOG: Validation of dependencies succeeded.
  LOG: Bind to native image succeeded.
  Attempting to use native image C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a86698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll.
  Native image successfully used.
  </code></pre>