Can't Add View from Controller in VS 2015 : “There was an error running the selected code generator”

前端 未结 21 2072
独厮守ぢ
独厮守ぢ 2020-11-27 18:34

I\'m following a video tutorial where I\'m required to create an empty ASP.NET Web Application with MVC, using Visual Studio 2015, bei

相关标签:
21条回答
  • 2020-11-27 19:13

    I had this issue with a different error message "-1 is outs the bounds of.."

    The only thing that worked for me, was to remove the project from the solution by right clicking the project and selecting 'Remove'. Then right click the solution, Add Existing Project, and selecting the project to reload it into the solution.

    After reloading the project, I can now add views again.

    0 讨论(0)
  • 2020-11-27 19:13

    I have the same error but in VS 2017 when I create a controller. I did it in the same way as @sh.alawneh wrote. Also, I tried to do what @longday wrote. But It didn't work. Then I tried in another way:

    • Right click on the target folder.
    • From the list, choose Add => New Item.

    There I choose a new controller and it works fine.

    Maybe I'll help someone.

    0 讨论(0)
  • 2020-11-27 19:13

    I just restarted my visual studio and it worked.

    0 讨论(0)
  • 2020-11-27 19:13

    My problem was the Types used in the Model Class.

    Using the Types like this:

        [NotMapped]
        [Display(Name = "Image")]
        public HttpPostedFileBase ImageUpload { get; set; }
    
    
        [NotMapped]
        [Display(Name = "Valid from")]
        public Nullable<DateTime> Valid { get; set; }
    
    
        [NotMapped]
        [Display(Name = "Expires")]
        public Nullable<DateTime> Expires { get; set; }
    

    No longer works in the Code Generator. I had to remove these types and scaffold without them, then add them later.

    It is silly, [NotMapped] used to work when scaffolding.

    Use the base Types: int, string, byte, and so on without Types like: DateTime, List, HttpPostedFileBase and so on.

    0 讨论(0)
  • 2020-11-27 19:15

    Lets assume you are using a datacontext in a DLL, well, it was my case, and I dont know why I have the same error that you describe, I solve it creating a datacontextLocal on the backend project. then I pass the Dbset to the correct datacontext and delete the local (you can let it there if you want, can be helpfull in the future

    if you ready are using it in local datacontext, create a new one and then pass the Dbset to the correct one

    0 讨论(0)
  • 2020-11-27 19:17

    I am working on a Core 3 app and had this issue pop up when adding a controller. I figured out that the Microsoft.VisualStudio.Web.CodeGeneration.Design package was updated with a .net 4.x framework dll. Updating to the project to Core 3.1 fixed the issue.

    0 讨论(0)
提交回复
热议问题