Scaffolding controller doesn't work with visual studio 2013 update 2
Solution 1
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...
Solution 2
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
Solution 3
Solution
Make sure section
<connectionStrings>..</connectionStrings>
is after
<configSections>..</configSections>
Solution 4
Please run the following command in the Package Manager Console:
Uninstall-Package EntityFramework -Force
Install-Package EntityFramework
Uninstall-Package MvcScaffolding
Install-Package MvcScaffolding
Solution 5
I had the very same issue with Visual Studio 2013 Update 3, but only for the scaffolders working with Entity Framework. The issue is seemingly caused by the incompatibility between Entity Framework 6.1.0 and the scaffolders in Visual Studio 2013 Update 2 and above.
To upgrade EF do the following:
Uninstall-Package EntityFramework -Force
Install-Package EntityFramework
This answer is borrowed from here
After the upgrade the scaffolders are working fine for me. Make sure to install the new version in every project where Entity Framework is required.
Comments
-
awrigley almost 2 years
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:
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.
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.
-
awrigley almost 10 yearsSee point 2 in my question - I did not have any MVCScaffolding or T4Scaffolding installed. So your solution is not relevant. You don't mention if you have Visual Studio 2013 Update 2 installed - if you don't then you are not answering the question and you should remove your answer.
-
Farrukh Subhani almost 10 yearsI have VS 2013 update 2 installed. If you dont have MVCScaffolding or T4Scaffolding even then check your packages folder it might have an empty folder. If none of them is installed you can start from step 3. I had none of these installed and had this issue when i updated VS to update 2. I had to copy all Templates (deleted VB ones only) and kept all files as it is and followed above and it worked. Then I installed MVCMailer and Package Manager gave errors on init so had to remove them and retry and it worked again.
-
Farrukh Subhani almost 10 yearsI have added MVCMailer package today and it added T4Scaffolding.Core again and I reproduced the same error, after removing both packages the error still remains and after i followed step 4-8 Scaffolder worked again.
-
awrigley almost 10 yearsI have looked at your suggestions in detail. Essentially, they do NOT address the issue that I have. They address the issue where MVCScaffolding or T4Scaffolding were installed. That is not my case. Steps 3 onwards are nothing other than the standard instructions for scaffolding controllers. That is what I do anyway. Sorry, this is definitely not the solution to my problem.
-
awrigley almost 10 yearsI will try that when I get time to reinstall VS 2013 Update 2
-
awrigley over 9 yearsThe connection strings are fine, no problem there, so can rule that one out.
-
sming over 9 yearsFYI I'm on update 4 and these instructions sadly didn't work - same error.
-
awrigley over 9 yearsHave you tried the other suggestions on here? They didn't work for me, but if what works for me doesn't work for you, then maybe what doesn't work for me will work for you? Just hoping. Quite why the MS evangelists don't pick up on these problems, eg Scott Hanselman, and write a blog post with solutions is beyond me.
-
sming over 9 yearsyes I've tried them all barring Farrukh's, which you state is not really answering the question. regisbsb & Math's answers don't apply since we're using inline config strings.
-
rohancragg over 9 yearsThis fixed it for me. I had connStrings in a separate file for privacy reasons. Temporarily putting them back into the we,confi file (i.e. inline) fixed it for me (and I then moved them back as they were once I had the scaffolded controller and views).
-
rohancragg over 9 yearsYes. Fixed it for me anyway.
-
awrigley over 9 yearsI note that this does not answer the question, as my problem, as stated in the question, was different. I would not want anyone to be confused, so -1.
-
awrigley over 9 yearsI would suggest reading the FAQ on this site about how to use it. It is not intended to be a forum, with the thread swaying this way and that and diverging from the question. It is, instead, a Q&A site. Ie, you ask a question and other people suggest answers. They do not try to engage in a "conversation" about similar problems, as might happen on a forum. I don't intend to be rude or unfair, just trying to promote the correct use of this site as others did with me in the early days.
-
firepol over 9 yearsah ok I see, then I guess I should have published a same question, let somebody tell me it's a duplicate, then answer on my own question saying it's a different problem (same error message... different problem? Really?) and justify the duplicate because the solution is different? I love this website because I find solutions. And I don't like duplicates... anyway, thx for the feedback. I'll consider twice before posting working and useful solutions next time...
-
awrigley over 9 yearssorry, but you very clearly don't see. The error is similar or even the same, but your set up is different. You were NOT answering the question that I had asked and that is confusing to others.
-
firepol over 9 yearsI wrote in bold "for people who haven't installed any scaffolding nuget packages". That should not really confuse people who don't apply... anyway... sorry, feel free to delete the answer. When I googled for this VS bug I arrived here and in another similar stackoverflow question. Sometimes to find the good answer one needs to do many google searches... I was only thinking to help... next time I publish on my blog...
-
user510101 over 9 yearssee my answer...essentially, ensure that in web.config, the configSections element is the first element in the configuration, before the connectionStrings element
-
radu florescu over 9 yearsYes, I had some unwanted stuff in web.config
-
Jose over 9 yearsThis solution worked for me, although I was having a different problem with the error message: "...To reference the existing configuration use the Entity<T>() or ComplexType<T>() methods." I had installed VS2013 Update 4 and EF 6.1.2. What I did differently is change the DbSet<...> to IDbSet<...> in T4 templates which you can add by right-clicking on the web project Entity Framework>Customize Reverse Engineer Templates.
-
ThdK over 9 yearsThis sollution worked for me with Visual Studio Express 2013 for Web and EF 6.1.2. Thanks!
-
Geoff Gunter over 9 yearsWorked for me, I had both AppSettings and ConnectionStrings using configSource. Had to remove both to fix. Thank you!
-
awrigley over 9 yearsSorry, but I had not changed the model name. There is no error in my web.config. As stated clearly in the question, the problem was produced by upgrading Visual Studio 2013 to Update 2.
-
Jose A over 9 years@awrigley: Ah Perfect :) . Hate when those things happen. Will let the answer in there just in case someone present a similar problem. Thanks for clarifying.
-
Shiham about 9 yearsworked for me on VS 2013 Update 4, just commented out it and worked perfectly
-
chris vietor about 9 yearsThat worked for me. Comment out the line with the configSource attribute and copy the content from the configSource file for scaffoling.
-
Brice almost 9 yearsI had forgotten to add <connectionStrings> and </connectionStrings> around "<add name...". This points to the general solution being a webconfig error preventing the scaffolding to work.
-
ThrowingSpoon almost 9 yearsI found I had a carelessly put my entity framework contexts outside of the entityFramework section in my web.config
-
Treyphor almost 9 yearsChanging to use IDBSet instead of DbSet is what fixed it for me. Thanks!
-
hacker over 8 yearsVS 2015 also has this problem
-
regisbsb over 8 yearsIt's a know tooling problem and a reported bug.
-
Laurence Frost over 8 yearsChanging DbSet to IDbSet worked for me too. Thanks :)
-
sam1132 over 8 yearsMy guess is this issue isnt
-
Steven Edison over 7 yearsTried 50 different things and this one worked for me!
-
MusicAndCode over 7 yearsThe error is not the same "There was an error running the selected code generator: 'Exception has been thrown by the target of an invocation.'
-
Kevin LaBranche about 7 yearsJust a mention that this is still an issue. I use config source for my connections and app settings. I inlined my connections just to see if it worked and did (VS15 update 3 & EF 6.1.3). I have to use config source. When scaffolding I just tell the controller creation to not do the EF for me and on view creation I don't set the data context. Works for me anyway as the default scaffolding is never what I want.
-
EoRaptor013 about 7 yearsI'm having the problem with VS 2017! Three major versions of VS, and all have the same problem? Something's has to be wrong in the documentation or samples.
-
Tsagana Nokhaeva over 6 yearsI think this bug is left on purpose :) MS forces us to push our connection strings to VCS. There is no other way to explain this.
-
yibe over 5 yearsThank you very much!, you saved my day finally. This one worked to me!