“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:45

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.
查看更多
做个烂人
3楼-- · 2019-01-03 17:45

I am also having this issue with MSVS2013 Update 4 and EF 6.0 The message I was getting was:

    there was an error running the selected code generator.
A configuration for type XXXX has already been added ...[]

I have a model with around 10 classes. I scaffolded elements at the beginning of the project with no problems.

After some days adding functionality, I tried to scaffold another class from the model, but an error was keeping me from doing it.

I have tried to update MSVS from update 2 to update 4, comment out my OnModelCreating method and other ideas proposed with no luck.

As a temporary way to continue with the project, I created a different asp.net project, pasted there my model classes (I am using fluent api, so there is little annotation on them) and successfully created my controller and views.

After that, I pasted back the created classes to the original project and corrected some mistakes (mainly dbset names).

It seems to be working, although I suppose that I will still find mistakes related to relationships between classes (due to the lack of fluent configuration when created).

I hope this helps to other users.

查看更多
何必那么认真
4楼-- · 2019-01-03 17:45

I know i am out late, but it was so frustrating so I hope this may help a little ...

My issue was similar to many experience here, generic error message when trying to add a new view or use scaffolding to add a new controller.
I found out that mvc 5 and ef 6 modelbuilder are not good friends:

My Solution:
1.Comment out modelBuilder in your Context class.
2.Clean Solution, Rebuild Solution.
3.Add view and Controller via scaffolding
4. Uncomment modelbuilder.

Maybe a little unconventional - but it worked! (for me)

查看更多
登录 后发表回答