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

前端 未结 21 2074
独厮守ぢ
独厮守ぢ 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:21

    I ran into a similar issue that prevented the code generation from working. Apparently, my metadata had unknown properties or values. I must admit I did not try all the answers here but who really wants to reinstall vs or download any of the numerous Nuget packages being used.

    Cleaning the project worked for me (Build->Clean Solution) The generator was using some outdated binaries to build the controller and views. Cleaning the solution removed the outdated binaries and voilà.

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

    C:\Users\{WindowsUser}\AppData\Local\Microsoft\VisualStudio\16.0_8183e7d1\ComponentModelCache

    Remove from this folder for VS 2019 ....

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

    The issue has been resolved after installed EntityFramework from nuget package manager into my project. Please take a look on your project references which already been added EntityFramework. Finally I can add the view with template after I added EntityFramework to project reference.

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

    Right-click on the project under the solution and click unload Project,

    you will see that the project is unloaded, so now re right-click on it and press load project

    then try to add your controller

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

    I have been scratching my head with this one too, what i found in my instance was that an additional section had been added to my Web.config file. Commenting this out and rebuilding solved the issue and i was now able to add a new controller.

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

    I'm currently trying to familiarise myself with MVC 4. I've been developing with MVC 5 for a while, but I need to know MVC 4 to study for my MCSD certification. I'm following a tutorial via Pluralsight, targeting much older versions of Entity Framework, and MVC, (the video was released in 2013!)

    I hit this exact same error 2 hours ago and have been tearing my hair out trying to figure out what is wrong. Thankfully, because the project in this tutorial is meaningless, I was able to step backward throughout the process to figure out what it was that was causing the object ref not set error, and fix it.

    What I found was an error within the structure of my actual solution.

    I had a MVC web project set up ('ASP.NET Web Application (.NET Framework)'), but I also had 2 class libraries, one holding my Data Access Layer, and one holding the domain setup for models connecting to my database.

    These were both of type 'Class Library (.NET Standard)'.

    The MVC project did not like this.

    Once I created new projects of type 'Class Library (.NET Framework)', and copied all the files from the old libraries to the new ones and fixed the reference for the MVC web project, a rebuild and retry allowed me to scaffold the View correctly.

    This may seem like an obvious fix, don't put a .NET Standard project alongside a .NET Framework one and expect it to work normally, but it may help others fix this issue!

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