25
votes

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
4
Have you tried to issue the cmd 'aspnet_regiis -I' again? Your Problem sounds a lot like a broken Installation of either VS or the IIS or a permissions issue. Have you altered the machine.config? Any difference using local IIS or IIS Express? - Ole Viaud-Murat
Thanks for your suggestion, but unfortunately (fortunately?) it started working again. After a couple of reboots and sleeps (normal usage) I decided to give it another try today and it magically worked. I don't know why the first reboot did not do the trick. I haven't changed anything with IIS or the machine.config. The site runs on IIS 7.5 (non express) by the way. - MikeyT
Ah, lovely. One of THOSE kind of errors. Guess I'll just wait and hope as well :( - Matt Sach
This error often occurs to me on a slow internet connection. I cannot deploy or update projects on anything less than 1mbps upload speed. - Ray Suelzer
Possibly a duplicate of: stackoverflow.com/questions/14637632/… or stackoverflow.com/questions/14653039/… all though this one has more details, and none of them have a real "solution" beyond that it eventually works - Arkaine55

4 Answers

3
votes

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.
0
votes

I would suggest following:

  1. Run Visual Studio in admin mode
  2. Try aspnet_regiis -I

I feel it's a permission issue.

0
votes

I just close visulstudio 2013 and reopen it in "Run as Administrator" mode. After that my problem solved and easily I added a view for the respective controller.

-1
votes

Have you checked in the .csproj file? I got a related (not exactly similar) issue when i started working on MVC for the first time, where i was not able to add View or Controller in VS2012 and i simply added the GUID {E3E379DF-F4C6-4180-9B81-6769533ABE47} and was able to add Views and Controllers.

Hope it helps resolve the problem!