“There was an error running the selected code gene

2019-01-03 17:10发布

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.

21条回答
相关推荐>>
2楼-- · 2019-01-03 17:36

This is usually related to a format of your Web.config

Rebuild solution and lookup under Errors, tab Messages. If you have any format problems with a web.config you will see it there. Fix it and try again.

Example: I had connectionstring instead of connectionString

查看更多
淡お忘
3楼-- · 2019-01-03 17:37

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.

查看更多
Explosion°爆炸
4楼-- · 2019-01-03 17:37

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.

查看更多
迷人小祖宗
5楼-- · 2019-01-03 17:38

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.

查看更多
倾城 Initia
6楼-- · 2019-01-03 17:38

I had this problem when trying to add an Api Controller to my MVC ASP.NET web app for a completely different reason than the other answers given. I had accidentally included a StringLength attribute with an IndexAttribute declaration for an integer property due to a copy and paste operation:

[Index]
[IndexAttribute("NumTrainingPasses", 0), StringLength(50)]
public int NumTrainingPasses { get; set; }

Once I got rid of the IndexAttribute declaration I was able to add an Api Controller for the Model that contained the offending property (NumTrainingPasses).

To help the search engines, here is the full error message I got before I fixed the problem:

There was an error running the selected code generator:

Unable to retrieve metadata for 'Owner.Models.MainRecord'. The property
'NumTrainingPasses' is not a String or Byte array. Length can only be configured for String or Byte array properties.

查看更多
劳资没心,怎么记你
7楼-- · 2019-01-03 17:42

I often run into this error working with MVC5 and EF when I create the models and context in a separate project (My data access layer) and I forget to add the context connection string to the MVC project's Web.Config.

查看更多
登录 后发表回答