Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaffolding controller doesn't work with visual studio 2013 update 2

PROBLEM:

I have updated to Visual Studio 2013 update 2 and now I cannot scaffold controllers.

The problem is not project specific: when I try to scaffold a controller, I get the following error in ALL and ANY project:

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

It was working before updating to Visual Studio 2013 update 2.

Have googled the issue to death, but none of the various suggestions work

Eg:

  1. Commenting out OnModelCreating in my context;

  2. Removing packages such as MvcScaffolding, etc (I have none installed and it doesn't work with ANY project);

I have modified/customised some of the templates, but it was working after the changes.

EDIT:

I uninstalled Visual Studio 2013 Update 2 and thereby reverted to Visual Studio version 12.0.21005.1 REL.

The problem has disappeared. Therefore, the problem is quite definitely with Update 2.

QUESTION:

Does anyone (including Microsoft) know of a fix?

EDIT 2:

Farruk Subhani's answer does not address the question: The question clearly states that removing references to MVCScaffolding does not solve the issue.

I have added a 200 point bounty, please address the question as clearly stated.

like image 519
awrigley Avatar asked May 28 '14 11:05

awrigley


People also ask

How to enable scaffolding in Visual Studio?

In Visual Studio, select Tools and then Extensions and Updates. From this dialog search the Visual Studio Gallery for Web Forms Scaffolding. For more information, see Web Forms Scaffolding.

How to use scaffolding in MVC?

To add a scaffold, right-click on Controllers folder in the Solution Explorer and select Add → New Scaffolded Item. It will display the Add Scaffold dialog. Select MVC 5 Controller with views, using Entity Framework in the middle pane and click 'Add' button, which will display the Add Controller dialog.

What is scaffolding in asp net core?

Scaffolding in ASP.NET Core is a technique used to generate code at design time to support a number of common application scenarios when working with Entity Framework Core. The code generation tool is available as a Nuget package.


2 Answers

Hey for all of you that nothing works, the real answer is you need to remove ANYTHING that has a configSource on the web.config and the connection string needs to be inlined.

EDIT:

Someone pointed out that it needs to be only <configSettings>, <appSettings>, and <connectionStrings> tags NOT using a configSource attribute. And that he was still able to use configSource attributes elsewhere, such as the rewriter tag.

I think it's that the tooling cannot follow configSource locations for the stuff it uses like connection strings and application settings.

Microsoft should be on this issue if not fixed yet.

EDIT 2:

Even thought @awrigley has marked his answer as correct it's a known Visual Studio bug. I've managed to tell then and I think it will get some attention soon. https://github.com/aspnet/Tooling/issues/169#issuecomment-144197015

like image 58
regisbsb Avatar answered Sep 20 '22 23:09

regisbsb


A combination of things have worked for me:

  1. Upgrade to Visual Studio 2013 Update 3.

  2. Upgrade Entity Framework to 6.1.1

  3. Modify the context configuration to use IDbSet<...> instead of DbSet<...> (I have heard that this can affect using async actions, but not apparently in my case, as I use this in my login actions, etc, as supplied by ASP.NET Identity 2 sample Nuget package).

Quite why this combination works, I have no idea. But then given the thundering silence from MS, I am probably not alone. I guess update 2 just didn't work...

like image 28
awrigley Avatar answered Sep 18 '22 23:09

awrigley