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

Brian Webb picture Brian Webb · Nov 12, 2013 · Viewed 90k times · Source

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.

Answer

Bill B picture Bill B · Aug 17, 2014

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.