C# – Visual Studio 2013 error getting AppDomain when adding a view or controller

asp.net-mvccvisual-studio-2013

In Visual Studio 2013 in a fresh C# MVC 4 empty project I right click the controllers folder and select Add -> Controller... then select a name for the controller and click Add. I get the following error popup:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates\AddController\Controller.tt(-1,-1): error: There was a problem getting an AppDomain to run the transformation from the host. The process cannot continue.

This also occurs when adding a view to the views folder using corresponding context menu option.

Question: what is the next step to troubleshoot this?

What I've tried so far:

Additional context:

  • Before I got this error I was able to successfully add multiple controllers and views without a problem. No visual studio restart or anything unusual happened between the successful and failed attempts.
  • I can go through the Add New Item dialogue and successfully add a controller or view, but the context menu Add -> Controller and Add -> View give the above error.
  • I have Visual Studio 2013 Update 4
  • Extensions I have added:
    • .net reflector,
    • attach to anything,
    • rename visual studio window title,
    • slowcheetah – xml transforms,
    • team foundation server power tools 2013,
    • visual studio 2013 color theme editor,
    • web essentials 2013 for update 4,
    • wix toolset

Best Answer

Additional things to check, as I've seen this happen before on Vista and newer operating systems:

  1. Owner of the IIS directory: If the owner of the IIS directory is different from the user running IIS and Visual Studio, it can cause issues, there are numerous scripts to take ownership of a directory, command lines you can run, or use the advanced security dialog.
  2. Permissions: Related to the problem with the owner above, I've had problems where the user running Visual Studio or IIS did not have appropriate permissions to access the directory or application pool.
  3. Running as Admin: I've had issues with IIS when not running Visual Studio as an admin, if you run Visual Studio as an admin, a lot of the issues related to the above two issues will resolve themselves, or go away completely; I'm aware this is not always an option to all developers.