title: Can't debug azure solution after upgrading to sdk 2.2. Solution runs fine without debugging. Can attach debugger to running emulator
body: <p>I have a cloud solution with 2 roles: 1 web role, 1 worker role. The solution has recently been upgraded from sdk 2.1 where it worked fine.</p>
  
  <p>If I run the solution without debugging e.g Ctrl-F5 the emulator fires up and the roles function as required. I can even attach a debugger to the running roles, though I have missed all role initialization by that point. </p>
  
  <p>If I run with debugging e.g F5, the emulator starts up; the worker role gets stuck at "Role state busy", the web role gets stuck at "Role unhealthy" and visual studio becomes unresponsive and needs Task manager to kill. In VS the deploy animation in the lower RHS keeps running. Even if I comment out all the OnStart and Run overrides of the RoleEntryPoint s the same happens. I cannot hit any breakpoints no matter how early in app lifecycle so I am pretty sure it is an emulator infrastructure/ vs debugger issue.</p>
  
  <p>I am currently running with assembly bind logging on and haven't noticed anything out of the ordinary. I have checked and rechecked that the sdk references in all projects and all dependencies have been upgraded.</p>
  
  <p>If I run with debugging and with Role diagnostics enabled I get entries related to configuration updates added to the output even when everything else is frozen. e.g:</p>
  
  <pre><code>    [Diagnostics]: Checking for configuration updates 10/01/2014 
  </code></pre>
  
  <p>I am looking for new lines of investigation, having exhausted everything I can think of. Incidentally this is not machine specific, I have tested on several machines and they all exhibit this behavior.</p>
  
  <p>EDIT: I should note that other cloud solutions are debuggable even with the 2.2 sdk. </p>
  
  <p>UPDATE: I am getting the following in the logs:</p>
  
  <pre><code>&lt;Log&gt;
      &lt;Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"&gt;
      &lt;System&gt;
          &lt;Provider Name="Application Hang"/&gt;
          &lt;EventID Qualifiers="0"&gt;1002&lt;/EventID&gt;
          &lt;Level&gt;2&lt;/Level&gt;
          &lt;Task&gt;101&lt;/Task&gt;
          &lt;Keywords&gt;0x80000000000000&lt;/Keywords&gt;
          &lt;TimeCreated SystemTime="2014-01-17T18:53:34.000000000Z"/&gt;
          &lt;EventRecordID&gt;1216077&lt;/EventRecordID&gt;
          &lt;Channel&gt;Application&lt;/Channel&gt;
          &lt;Computer&gt;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;/Computer&gt;
          &lt;Security/&gt;
      &lt;/System&gt;
      &lt;EventData&gt;
          &lt;Data&gt;devenv.exe&lt;/Data&gt;
          &lt;Data&gt;12.0.21005.1&lt;/Data&gt;
          &lt;Data&gt;2910&lt;/Data&gt;
          &lt;Data&gt;01cf13b4114dc59b&lt;/Data&gt;
          &lt;Data&gt;4294967295&lt;/Data&gt;
          &lt;Data&gt;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe&lt;/Data&gt;
          &lt;Data&gt;a94194c4-7fa8-11e3-bed7-001e4fea6057&lt;/Data&gt;
          &lt;Data/&gt;
          &lt;Data/&gt;
          &lt;Binary&gt;54006F00700020006C006500760065006C002000770069006E0064006F0077002000690073002000690064006C00650000000000&lt;/Binary&gt;
      &lt;/EventData&gt;
  &lt;/Event&gt;
  &lt;Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"&gt;
  &lt;System&gt;
      &lt;Provider Name="ASP.NET 4.0.30319.0"/&gt;
      &lt;EventID Qualifiers="49152"&gt;1325&lt;/EventID&gt;
      &lt;Level&gt;2&lt;/Level&gt;
      &lt;Task&gt;0&lt;/Task&gt;
      &lt;Keywords&gt;0x80000000000000&lt;/Keywords&gt;
      &lt;TimeCreated SystemTime="2014-01-17T18:56:06.000000000Z"/&gt;
      &lt;EventRecordID&gt;1216080&lt;/EventRecordID&gt;
      &lt;Channel&gt;Application&lt;/Channel&gt;
      &lt;Computer&gt;xxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;/Computer&gt;
      &lt;Security/&gt;
  &lt;/System&gt;
  &lt;EventData&gt;
      &lt;Data&gt;Failed to initialize the AppDomain:/LM/W3SVC/6/ROOTException: System.SystemExceptionMessage: Failed to create AppDomain.StackTrace:    at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)   at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)InnerException: System.Runtime.InteropServices.COMExceptionMessage: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))StackTrace:    at System.Security.Policy.PEFileEvidenceFactory.GetLocationEvidence(SafePEFileHandle peFile, SecurityZone&amp;amp; zone, StringHandleOnStack retUrl)   at System.Security.Policy.PEFileEvidenceFactory.GenerateLocationEvidence()   at System.Security.Policy.PEFileEvidenceFactory.GenerateEvidence(Type evidenceType)   at System.Security.Policy.AssemblyEvidenceFactory.GenerateEvidence(Type evidenceType)   at System.Security.Policy.Evidence.GenerateHostEvidence(Type type, Boolean hostCanGenerate)   at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)   at System.Security.Policy.Evidence.GetHostEvidence(Type type, Boolean markDelayEvaluatedEvidenceUsed)   at System.Security.Policy.AppDomainEvidenceFactory.GenerateEvidence(Type evidenceType)   at System.Security.Policy.Evidence.GenerateHostEvidence(Type type, Boolean hostCanGenerate)   at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)   at System.Security.Policy.Evidence.GetHostEvidence(Type type, Boolean markDelayEvaluatedEvidenceUsed)   at System.Security.Policy.Evidence.GetHostEvidence[T]()   at System.Web.Hosting.ApplicationManager.GetDefaultDomainIdentity()   at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)&lt;/Data&gt;
  &lt;/EventData&gt;
  &lt;/Event&gt;
  &lt;Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"&gt;
  &lt;System&gt;
      &lt;Provider Name="ASP.NET 4.0.30319.0"/&gt;
      &lt;EventID Qualifiers="49152"&gt;1325&lt;/EventID&gt;
      &lt;Level&gt;2&lt;/Level&gt;
      &lt;Task&gt;0&lt;/Task&gt;
      &lt;Keywords&gt;0x80000000000000&lt;/Keywords&gt;
      &lt;TimeCreated SystemTime="2014-01-17T18:56:06.000000000Z"/&gt;
      &lt;EventRecordID&gt;1216080&lt;/EventRecordID&gt;
      &lt;Channel&gt;Application&lt;/Channel&gt;
      &lt;Computer&gt;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;/Computer&gt;
      &lt;Security/&gt;
  &lt;/System&gt;
  &lt;EventData&gt;
      &lt;Data&gt;Failed to initialize the AppDomain:/LM/W3SVC/6/ROOTException: System.SystemExceptionMessage: Failed to create AppDomain.StackTrace:    at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)   at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)InnerException: System.Runtime.InteropServices.COMExceptionMessage: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))StackTrace:    at System.Security.Policy.PEFileEvidenceFactory.GetLocationEvidence(SafePEFileHandle peFile, SecurityZone&amp;amp; zone, StringHandleOnStack retUrl)   at System.Security.Policy.PEFileEvidenceFactory.GenerateLocationEvidence()   at System.Security.Policy.PEFileEvidenceFactory.GenerateEvidence(Type evidenceType)   at System.Security.Policy.AssemblyEvidenceFactory.GenerateEvidence(Type evidenceType)   at System.Security.Policy.Evidence.GenerateHostEvidence(Type type, Boolean hostCanGenerate)   at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)   at System.Security.Policy.Evidence.GetHostEvidence(Type type, Boolean markDelayEvaluatedEvidenceUsed)   at System.Security.Policy.AppDomainEvidenceFactory.GenerateEvidence(Type evidenceType)   at System.Security.Policy.Evidence.GenerateHostEvidence(Type type, Boolean hostCanGenerate)   at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)   at System.Security.Policy.Evidence.GetHostEvidence(Type type, Boolean markDelayEvaluatedEvidenceUsed)   at System.Security.Policy.Evidence.GetHostEvidence[T]()   at System.Web.Hosting.ApplicationManager.GetDefaultDomainIdentity()   at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)&lt;/Data&gt;
  &lt;/EventData&gt;
  &lt;/Event&gt;
  &lt;/Log&gt;
  </code></pre>