(VS2017) There was an error running the selected code generator: 'Sequence contains no elements'

前端 未结 13 2269
忘了有多久
忘了有多久 2021-01-04 11:34

I\'m running through one of Microsoft\'s tutorials on MVC development and I\'m getting errors when trying to create various elements; Views, Controllers, etc.

The e

相关标签:
13条回答
  • 2021-01-04 11:58

    Visual Studio 2019 and .net core 3.0

    Uninstalled: Microsoft.VisualStudio.Web.CodeGeneration.Design Version: 3.1.0-preview3.19558.8

    and Installed: Microsoft.VisualStudio.Web.CodeGeneration.Design Version: 3.0.0

    Solved the issue for me.

    0 讨论(0)
  • 2021-01-04 12:00

    Uninstalling and reinstalling VS2017 did not work. I can create classes, items and other lesser elements. However, the issues with creating Controllers, View, etc. persists.

    0 讨论(0)
  • 2021-01-04 12:02

    I've upvoted @James's comment because it worked for me, but I wanted to add it as an answer to make it more visible to others:

    Open the package manager console:

    Tools > Nuget Package Manager > Package Manager Console

    Type:

    dotnet restore
    

    No restart / reinstall required.

    0 讨论(0)
  • 2021-01-04 12:03

    Error will occur if you had different instances of connection strings in your web.config

    Comment out the other not needed or necessary connection strings tags then rebuild your solution. That would be all

    0 讨论(0)
  • 2021-01-04 12:05

    My project had a warning against one of the dependancies (Microsoft.VisualStudio.Web.CodeGeneration.Design). I removed that dependancy and then rebuilt the project.

    I then added a new Razor page and the dependancy was readded to the project - with an earlier version (2.1.9) and I can now add Razor pages without issue.

    0 讨论(0)
  • 2021-01-04 12:08

    I had this trying to add an Empty API Controller in an ASP.NET Core Web Application (API template). I found in Project Properties the Target Framework wasn't set. I set it to .NET Core 2.1.

    If you then try to add the controller you will get an error because this line of code was added to Startup.cs

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    

    and CompatibilityVersion doesn't have an enum for Version2_2, so change it to 2_1:

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    

    and now it adds the controller ok.

    I was getting this with a totally new project. Visual Studio 2017 15.9.11.

    I had already tried the dotnet restore and clearing the ComponentModelCache.

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