title: How to debug a 0xc0000409 error in PerfMon.dll? / AssemblyBinding
body: <h2>Problem description</h2>
  
  <p>I am trying to debug a problem on a customer's server (Win 2012R2) where one of our .NET Web Applications is hosted in their IIS (version 8.5.9600.16384).
  Recently, one of our technical supports changed a minor internal setting in the Web.config file of the application and according to them, nothing else was changed or done to the system. The application was not updated either, and had been running without any issues before.</p>
  
  <p>Since that change, the AppPool in which the site is configured cannot be started anymore. According to the System Event logs, there are a few attempted starts, each resulting in a worker process crash, until the Rapid-Fail Protection of the pool stops the startup process entirely.</p>
  
  <p>Also, since I'm on a customer's server, I only have limited debugging options.</p>
  
  <h2>Findings</h2>
  
  <p>Reported in the System Event log by WAS:</p>
  
  <blockquote>
    <p>A process serving application pool '[our pool]' suffered a fatal communication error with the Windows Process Activation Service. The process id was '5664'. The data field contains the error number.</p>
    
    <p>Application pool '[our pool]' is being automatically disabled due to a series of failures in the process(es) serving that application pool.</p>
  </blockquote>
  
  <p>A look at the corresponding Application Error log reveals the following:</p>
  
  <blockquote>
    <p>Faulting application name: w3wp.exe, version: 8.5.9600.16384, time stamp: 0x52157ba0
    Faulting module name: PerfMon.dll, version: 8.0.10977.0, time stamp: 0x59cfb424
    Exception code: 0xc0000409
    Fault offset: 0x000f8c7b
    Faulting process id: 0x1620
    Faulting application start time: 0x01d423ff75bef49f
    Faulting application path: C:\Windows\SysWOW64\inetsrv\w3wp.exe
    Faulting module path: C:\Program Files\Microsoft Monitoring Agent\Agent\APMDOTNETAgent\V8.0.10918.0\PerfMon.dll
    Report Id: b56327b3-8ff2-11e8-80d5-005056a52299
    Faulting package full name: 
    Faulting package-relative application ID: </p>
  </blockquote>
  
  <p>While googling for this problem I mainly focused on PerfMon.dll issues and the provided error code 0xc0000409, which is apparently either related to a corrupted registry entry or a Stack Buffer Overflow, but in both cases I've simply been unable to figure out what the cause could be. </p>
  
  <p>I also tried the crash dump analysis described here
  <a href="https://blogs.msdn.microsoft.com/parvez/2016/08/06/iis-application-pool-crash-and-debug-diag/" rel="noreferrer">https://blogs.msdn.microsoft.com/parvez/2016/08/06/iis-application-pool-crash-and-debug-diag/</a></p>
  
  <p>But in the end it seemed like it was just a round-trip back to the original problem, as this was the only error found in the dump:</p>
  
  <blockquote>
    <p>The assembly instruction at PerfMon!DllGetClassObject+966fb in C:\Program Files\Microsoft Monitoring Agent\Agent\APMDOTNETAgent\V8.0.10918.0\PerfMon.dll from Microsoft Corp. has caused an unknown exception (0xc0000409) on thread 2</p>
  </blockquote>
  
  <p>Which is basically what I've gotten from the event log already.</p>
  
  <p>My main question here is not only what might be the cause and a potential fix to this problem, but also how to properly find the cause/solution in the first place.</p>
  
  <h2><strong>UPDATE</strong></h2>
  
  <p>Using Fusion Logs, I was able to find three binding errors for <strong>System.Web.DynamicData</strong>, <strong>System.Web.Extensions</strong> and <strong>System.ServiceModel.web</strong>.</p>
  
  <blockquote>
    <p>The operation failed.
    Bind result: hr = 0x80004005. Unspecified error</p>
    
    <p>Assembly manager loaded from:  >C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
    Running under executable  C:\Windows\SysWOW64\inetsrv\w3wp.exe
    --- A detailed error log follows. </p>
    
    <p>=== Pre-bind state information ===
    LOG: DisplayName = System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
     (Fully-specified)
    LOG: Appbase = [app root path]
    LOG: Initial PrivatePath = [app root bin directory]
    LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\bee9e73a
    LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\bee9e73a
    LOG: AppName = b83a4ee
    Calling assembly : (Unknown).</p>
    
    <p>Rejecting code sharing because a dependent assembly did not match the conditional APTCA share mode</p>
  </blockquote>
  
  <p>Searching for any information on this I was only able to find an old error related to MVC3/MVC4, which required a configuration change. That is unrelated to this issue, though.
  This might also mean that the original error has nothing to do with the PerfMon at all and that the original error is just a weird side effect.</p>