"There was an error running the selected code generator" in VS 2013 scaffolding

105,319

Solution 1

Problem was with a corrupted web.config and package directory.

I created the new project, and copied my code files over to the new working project, I later went back and ran diffs on the config files and a folder diff on the project itself.

The problem was that the updates had highly junked up my config file with lots of update artifacts that I ended up clearing out.

The second problem was that the old project also kept hanging onto older DLLs that were supposed to be wiped with the application of the Nuget package. So I wiped the obj and bin folders, then the package folder. After that was done, I was able to get the older project repaired and building cleanly.

I have not looked into why the config file or the package folder was so borked, but I'm assuming it is one of two things.

  1. Possibly the nuget package has a flaw
  2. The TFS source control blocked nuget from properly updating the various dependencies.

Since then, before applying any updates, I check out everything. However, since I have not updated EF in a while, I no evidence that this has resolved my EF or scaffolding issue.

Solution 2

VS2013 Error: There was an error running the selected code generator: ' A configuration for type 'SolutionName.Model.SalesOrder' has already been added ...'

I had this problem while working through a Pluralsight Course "Parent-Child Data with EF, MVC, Knockout, Ajax, and Validation". I was trying to add a New Scaffolded Item using the template MVC 5 Controller with views, using Entity Framework.

The Data Context class I was using including an override of the OnModelCreating method. The override was required to add some explicit database column configurations where the EF defaults were not adequate. This override was simple, worked and no bugs, but (as noted above) it did interfere with the Controller scaffolding code generation.

Solution that worked for me:

1 - I removed (commented out) my OnModelCreating override and the scaffolding template completed with no error messages - my controller code was generated as expected.

2 - However, trying to build the project choked because 'The model had changed'. Since my controller code was was now properly generated, I restored (un-commented) the OnModelCreating override and the project built and ran successfully.

Solution 3

I was able to resolve this issue and have a little better understanding of what was going on. The best part is that I am able to recreate the issue and fix it to be sure of my explanation here. The resolution was to install exactly same version of Entity Framework for both Data Access Layer project and the Web Project.

My data access layer had Entity Framework v6.0.2 installed using NuGet, the web project did not have Entity Framework installed. When trying to create a Web API Controller with Entity Framework template Entity Framework gets installed automatically but its one of the older version 6.0.0. I was surprised to see two version of Entity Framework installed, newer on my Data Layer project and older on my Web Project. Once, I removed the older version and installed the newer version on Web Project the problem went away.

Solution 4

I tried every answer on every website I found, and nothing worked... until this. Posting late in case anyone like me comes along and has the same frustrating experience as I have.

My issue was similar to many here, generic error message when trying to use scaffolding to try and add a new controller (ef6, webapi). I initially was able to use scaffolding for about 15 controllers, after that it just stopped working one day.

Final Solution:

  1. Open your working folder on your hard drive for your solution.
  2. Delete everything inside the BIN folder
  3. Delete everything inside the OBJ folder
  4. Clean Solution, Rebuild Solution, Add Controller via scaffolding

Voila! (for me)

Solution 5

I checked all my projects and each had the same version of Entity Framework. In my case, the problem was that one of my projects was targeting .Net 4.0 while the rest were .Net 4.5.

Solution:

  1. For each project in solution Project->Properties->Application: Set Target Framework to .Net 4.5 (or whatever you need).
  2. Tools->Manage NuGet Package for Solution. Find Installed “Entity Framework”. And click Manage. Uncheck all projects (note the projects that require EF). Now, Re-Manage EF and check that projects that you need.
  3. Clean and Rebuild Solution.
Share:
105,319
Brian Webb
Author by

Brian Webb

Intro: I'm not a genius by any means, but I do with what I have to help others. Background: 1980s Engineering Assembly - 6502 C - Intel, DOS COBOL - HP Mainframe (Bragging rights, but no details remembered) EET from a defunct school Personal Projects Started Biblical studies Illustration arts 1990s Engineering BBx - Intel, DOS (Still can do badic, but BBx is mostly forgotten.) ANSI Basic - Intel, DOS VB/VBA - MS Office, CorelDraw, Windows 3.x C/C++ - Windows Personal Projects Ordained Christian Minister Illustraton via Corel Graphics Suite 2000s Engineering .NET/Mono Embedded via Arduino Taught XML at the XML Symposium in Costa Mesa, CA 2003. Personal Projects Maintained Ordained Christian Minister Status Maintained skills for Corel Graphics Suite 2010s Engineering .NET/MONO .NET MicroFramework .NET / Windows 10 IOT .NET / CORE C / C++ / C# / JavaScript Arduino Raspberry Pi 2B & 3B Angular.js Node.js TypeScript For Node.js Angular Twitter Bootstrap Architected solutions to take advantage of Azure. Team skills Certified Product Owner Agile Project Management trained Inhouse Catalytic Coaching Promoter/Coach Personal Projects Maintained Ordained Christian Minister Status Wrote Christian Freedom 1st Ed. Maintained skills for Corel Graphics Suite 2020 Goals Get many IT/IS MS certifications. Maintain existing skills, while expanding Grow LCPtracker, Inc., as an industry technology leader. Convert the coming zombie apocalypse into a business opportunity where everyone wins, including the zombies.

Updated on July 09, 2022

Comments

  • Brian Webb
    Brian Webb almost 2 years

    I'm creating a new view off of a model.
    The error message I am getting is

    Error
    There was an error running the selected code generator:
    'Access to the path
    'C:\Users\XXXXXXX\AppData\Local\Temp\SOMEGUID\EntityFramework.dll' is denied'.

    I am running VS 2013 as administrator.

    I looked at Is MvcScaffolding compatible with VS 2013 RC by command line? but this didn't seem to resolve the issue.

    VS2013 C#5 MVC5 Brand new project started in VS 2013.

  • Brian Webb
    Brian Webb almost 10 years
    Not in my case. If you look at what was tagged as answer, it was a mismatch of dependencies. It was solved by purging the nuget cache, and downloading only the latest of each library for the assemblies. Though I can see where your case could be a damaged web.config file.
  • Brian Webb
    Brian Webb over 9 years
    That isn't a bug. OnModelCreating describes your model to the EF framework, so it knows how to work with it. Even if you don't use that feature, it is still referenced under the hood. This is why DbModelBuilder is passed as part of the function call. You then can use modelBuilder to extend the various entities that you are working with. These descriptions cover things like cascading updates and optional references as defined in your schema.
  • Brian Webb
    Brian Webb over 9 years
    What you described wasn't a scaffolding issue, but a post scaffold issue where you injected your own bug into the code by overriding the OnModelCreating. Though, I hope this gives other people a heads up on that risk. So thanks for posting.
  • Brian Webb
    Brian Webb over 9 years
    If possible, you may want to switch to EF 6. Apparently there were some changes to the OnModelCreating process that makes coding against it more reliable. I noticed that on my newer model libs that I don't have problems with the OnModelCreating process.
  • olf
    olf over 9 years
    I am following the same course as above, but using EF 6 (and VS 2013 as well). And I get the same error. In the above step 1, remember to rebuild the solution after commenting out the OnModelCreating or it wont create a new scaffolded item.
  • etechpartner
    etechpartner over 8 years
    This specific answer and especially olf's comment above unblocked me on the same tutorial. Thanks for adding the comments here.
  • Stack0verflow
    Stack0verflow over 8 years
    Well, I have only one project in the solution.
  • Brian Webb
    Brian Webb over 8 years
    Make sure that you have everything checked out, and if your solution is made up of multiple projects, then each project will have to have it's dependencies updated too. Then try again. The vast majority of the people who have tried this works, so the odds are, you have a file, or something that is still locked, and preventing this correction from working.
  • Saeedouv
    Saeedouv about 8 years
    I checked the versions and the were exactly the same, anyway, in the web api project i removed reference to EntityFramework and EntityFramework.SqlServer and re-added them then everything worked fine
  • Tom McDonald
    Tom McDonald over 7 years
    this was the answer for me. My configSections wasnt the first child node of configuration node (I squeezed connectionStrings node in there). Of course VS2015 didn't provide any help with the ambiguous error message. I didn't figure it out until I undid web.config changes.
  • jimboweb
    jimboweb over 7 years
    Deleting the packages also worked for me. None of the other solutions listed here or in other answers to the same question worked.
  • Phil3992
    Phil3992 about 7 years
    Just to add rebuilding for some reason twice resolved this for me. Looks like the error is very genric as so many different answer seem to resolve it what apprenelty is the error.
  • Brian Webb
    Brian Webb almost 4 years
    This was resolved and closed years ago. It was caused by file locking from the source control.
  • TylerH
    TylerH over 3 years
    The question says OP is already running VS as an admin.
  • Vicky Gupta
    Vicky Gupta about 2 years
    probably the best solution : )