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

This is typically caused by an invalid Web.config file. I had the same problem and it turned out I inadvertently changed the HTML comment block <!-- --> to a server side comment block @* *@ (through a Replace All action).

And in case you are developing a WinForms application, try to look to App.config.

查看更多
劫难
3楼-- · 2019-01-03 17:20

For us it has something to do with build configurations, where we have a Debug|x64 build configuration that we had recently switched to using, which in retrospect seemed to be when the scaffolding stopped working.

(I suspect that there are at least 10 different things that can cause this, as evidenced by the various answers on SO that some people find to work for them--but which don't work for others, so I'm not suggesting my solution will work for everyone).

What worked for us (using VS 2013 Express for Web on 64 bit Windows 7):

It (scaffolding) was NOT working in Debug|x64 Build configuration. But doing the following (and it seems like every step is necessary--couldn't figure out how to do it in a more streamlined way) seems to work for us.

  1. First, switch to Debug|x86--use Solution (right-click) Configuration Manager for all the projects in your solution. (Debug|Any CPU may also work).
  2. Clean your solution.
  3. Shut down Visual Studio. (cannot get it to work if I skip this).
  4. Open Visual Studio.
  5. Open your solution.
  6. Build your solution.
  7. Now try adding scaffolding items; for us, it worked at this point, we no longer got the error message saying something about "There was an error running the selected code generator".

If you need to switch back to a scaffolding-non-working build configuration, you can do so, after you've scaffolded everything you need to for the moment. We switched back to our Debug|x64 after scaffolding what we needed to.

查看更多
看我几分像从前
4楼-- · 2019-01-03 17:20

I have seen this error with a new MVC5 project when referencing a model from a different project. Checking the path, EntityFramework.dll did exist. It was read-only though. Process monitor showed that there was an error attempting to delete the file. Setting the EntityFramework.dll in my packages folder (copy stored in source control) to writeable got around this error but brought up another one saying that it couldn't load the EntityFramework assembly because it didn't match the one referenced. My model class was defined in a different project that was using an older version of the entity framework. The MVC5 project was referencing EF 6 while the model was from a project references EF 4.4. Upgrading to EF 6 in the model's project fixed it for me.

查看更多
唯我独甜
5楼-- · 2019-01-03 17:21

Rebuild the solution works for me. before rebuild, I find references number of my 'ApplicationDbContext' is zero, that is impossible, so rebuild solution, everything is OK now.

查看更多
手持菜刀,她持情操
6楼-- · 2019-01-03 17:24

This happened to me when I attempted to create a new scaffold outside of the top level folder for a given Area.

  • MyArea
    | - File.cs (tried to create a new scaffold here. Failure.)

I simply re-selected my area and the problem went away:

  • AyArea (Add => new scaffold item)

Note that after scaffold generation you are taken to a place where you will not be able to create a new scaffold without re-selecting the area first (in VS 2013 at least).

查看更多
够拽才男人
7楼-- · 2019-01-03 17:28

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)

查看更多
登录 后发表回答