Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application can't scaffold items

I created an MVC 5 application in VS 2013 Professional and then used EF 6.1 code first with an existing DB on SQL Server Express. When I try to create the views I’m using the “New scaffolded item…” then selecting the “MVC 5 controller with views, using Entity Framework.” I select the model and context classes and click OK. Then the following error message appears and no code is created. I’ve uninstalled EF Power Tools with the same error.

Error

There was an error running the selected code generator: ‘Exception has been thrown by the target of an invocation.’

I've also tried uninstalling/reinstalling VS 2013 and SQL Server with no changes.

Any other ideas about what might cause this error?

like image 812
runamuk0 Avatar asked May 10 '14 01:05

runamuk0


People also ask

How do you add a new item to scaffolding?

From Solution Explorer, right-click on the project > Add > New Scaffolded Item. From the left pane of the Add Scaffold dialog, select Identity > Add. In the Add Identity dialog, select the options you want. Select your existing layout page so your layout file isn't overwritten with incorrect markup.

What is scaffolding in Visual Studio?

ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add code that interacts with data models.


2 Answers

In my case I moved my connection strings out of the Web.config to

<connectionStrings configSource="ConnectionStrings.config"/> 

that when I started getting the error when I was trying to scaffold.

There was an error running the selected code generator: ‘Exception has been thrown by the target of an invocation.’

Moving my connection strings back to the Web.config solved my issue.

like image 147
Developer SPM Avatar answered Sep 22 '22 01:09

Developer SPM


I had this problem too, I solved the problem by calling the base.onModelCreating in my DB context

base.OnModelCreating(modelBuilder); 
like image 26
Mhand7 Avatar answered Sep 21 '22 01:09

Mhand7