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:
Commenting out OnModelCreating in my context;
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.
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.
Does anyone (including Microsoft) know of a fix?
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.
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.
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.
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.
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
A combination of things have worked for me:
Upgrade to Visual Studio 2013 Update 3.
Upgrade Entity Framework to 6.1.1
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With