Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Add View from Controller in VS 2015 : "There was an error running the selected code generator"

I'm following a video tutorial where I'm required to create an empty ASP.NET Web Application with MVC, using Visual Studio 2015, being new to ASP.NET world, I'm following step by step.

I got my project created well, next step adding a View from an existing Controller, I got hit by a messagebox error saying :

Error :
There was an error running the selected code generator: 'Invalid pointer (Exception from HRESULT:0x80004003(E_POINTER))'

I Googled the problem, found similar issues, but none led to a clear solution, some similar problems were issued by anterior version of VisualStudio, but as I said none with a clear solution.

To clarify what I experienced, here's what I've done step by step :

Chosen a ASP.NET Web Application :

enter image description here

Chosen Empty Template with MVC checked :

enter image description here

Tried to Add View from a Controller :

enter image description here

Some settings ...

enter image description here

The Error :

enter image description here

What's causing this problem and What is the solution for it ?

Update :

It turns out that even by trying to add the View manually I get the same error, adding a view is all ways impossible !

like image 467
AymenDaoudi Avatar asked Jan 25 '16 12:01

AymenDaoudi


People also ask

How do you add a controller on VS code?

To add a controller, in Visual Studio Code right-click the Controllers folder and select New File. When the text box appears, enter CarsController. cs as the new file name. This will add a new C# file that will also open in the code editor.

How do you add a view to a controller?

Open the “HomeController” >> Set cursor inside the Action Method >> Right click on inside the action method >> click on [Add View] as follow. Provide the view name and select the appropriate layout and click on the “Add” button as follows.

How do you go from view to controller?

You can right click on the Index Method of the controller and you will see an option "Go To View" which will do exactly that.

How do I add a view in Visual Studio 2012?

In the project, add a view template that you can use with the Index method. To do this, right-click inside the Index method and click Add View. The Add View dialog box appears.


2 Answers

Try clearing the ComponentModelCache, the cache will rebuild next time VS is launched.

  1. Close Visual Studio
  2. Delete everything in this folder C:\Users\ [your users name] \AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
  3. Restart Visual Studio

14.0 is for visual studio 2015. This will work for other versions also.

like image 124
longday Avatar answered Oct 04 '22 09:10

longday


I had this issue with a different error message "-1 is outs the bounds of.."

The only thing that worked for me, was to remove the project from the solution by right clicking the project and selecting 'Remove'. Then right click the solution, Add Existing Project, and selecting the project to reload it into the solution.

After reloading the project, I can now add views again.

like image 45
lucky.expert Avatar answered Oct 04 '22 11:10

lucky.expert