title: ASP MVC 5 applications stopped working with "System.Security.SecurityException' in mscorlib.dll"
body: <p><strong>Partly solved the moment I hit save:
  The Exception settings of the failing solution were set to break on all for Common Language Runtime Exceptions". Resetting those to default allowed the project to start.</strong> </p>
  
  <p>This appears to be a solution level issue.</p>
  
  <p>I have a solution with half a dozen projects in including a web project created as an MVC project.</p>
  
  <p>I've not made any changes to it. it's been in the solution for a couple of months.</p>
  
  <p>Today it no longer run. Initially it threw an exception saying it couldn't access Temporary ASP.NET files in the ridiculous default location of C:\Windows... So I fixed that by adding tempDirectory="..."</p>
  
  <p>The next exception that occurs is:</p>
  
  <pre><code>System.Security.SecurityException occurred
  Message: Exception thrown: 'System.Security.SecurityException' in mscorlib.dll
  Additional information: Requested registry access is not allowed.
  </code></pre>
  
  <p>The stack trace at this point is:</p>
  
  <pre><code>mscorlib.dll!System.ThrowHelper.ThrowSecurityException(System.ExceptionResource resource)   Unknown
  mscorlib.dll!Microsoft.Win32.RegistryKey.OpenSubKey(string name, bool writable) Unknown
  mscorlib.dll!Microsoft.Win32.RegistryKey.OpenSubKey(string name)    Unknown
  System.Web.dll!System.Web.Util.Misc.OpenAspNetRegKey(string subKey) Unknown
  System.Web.dll!System.Web.Util.Misc.GetAspNetRegValue(string subKey, string valueName, object defaultValue) Unknown
  System.Web.dll!System.Web.Compilation.CompilationMutex.CompilationMutex(string name, string comment)    Unknown
  System.Web.dll!System.Web.Compilation.CompilationLock.CompilationLock() Unknown
  [Native to Managed Transition]  
  [Managed to Native Transition]  
  System.Web.dll!System.Web.Compilation.CompilationLock.GetLock(ref bool gotLock) Unknown
  System.Web.dll!System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(long cachedHash)  Unknown
  System.Web.dll!System.Web.Compilation.BuildManager.ExecutePreAppStart() Unknown
  System.Web.dll!System.Web.Hosting.HostingEnvironment.Initialize(System.Web.Hosting.ApplicationManager appManager, System.Web.Hosting.IApplicationHost appHost, System.Web.Configuration.IConfigMapPathFactory configMapPathFactory, System.Web.Hosting.HostingEnvironmentParameters hostingParameters, System.Security.Policy.PolicyLevel policyLevel, System.Exception appDomainCreationException) Unknown
  System.Web.dll!System.Web.Hosting.HostingEnvironment.Initialize(System.Web.Hosting.ApplicationManager appManager, System.Web.Hosting.IApplicationHost appHost, System.Web.Configuration.IConfigMapPathFactory configMapPathFactory, System.Web.Hosting.HostingEnvironmentParameters hostingParameters, System.Security.Policy.PolicyLevel policyLevel)  Unknown
  [AppDomain (DefaultDomain, #1) -&gt; AppDomain (/LM/W3SVC/2/ROOT-1-130855931402033459, #2)]    
  System.Web.dll!System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)    Unknown
  System.Web.dll!System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters) Unknown
  System.Web.dll!System.Web.Hosting.ApplicationManager.GetAppDomainWithHostingEnvironment(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)   Unknown
  System.Web.dll!System.Web.Hosting.ApplicationManager.CreateObjectInternal(string appId, System.Type type, System.Web.Hosting.IApplicationHost appHost, bool failIfExists, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)    Unknown
  System.Web.dll!System.Web.Hosting.ProcessHost.StartApplication(string appId, string appPath, out object runtimeInterface)   Unknown
  </code></pre>
  
  <p>If I create a new solution with a single web MVC web project in and run it, it starts correctly, showing the standard template.</p>
  
  <p>If I add a new project to the existing solution and run it, It does not run! It throws the same access exceptions.</p>
  
  <p>IF I add the existing failing project to the new working solution, it works!!</p>
  
  <p>I've tried deleting all temp asp.net files, all temp files generally, stopping stuff, rebooting. Nothing works. </p>
  
  <p>It's as if the solution has started with fewer rights for some reason. I'm not running either instance as administrator, and using the same shortcut icon to start VS.</p>
  
  <p>This is with Visual Studio 2015. Framework is set to 4.51</p>
  
  <p>Any clues at all?</p>