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

13,368

Solution 1

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.

Solution 2

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.

Solution 3

Try clearing the ComponentModelCache, the cache will rebuild next time VS is launched.

  1. Close Visual Studio Delete everything in this folder
  2. C:\Users\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
  3. Restart Visual Studio 14.0 is for visual studio 2015. This will work for other versions also.

Credit to https://stackoverflow.com/a/35815094/5209435

Edit

Are your providerNames in the connectionString section of your web.config file the same?

You may also want to try the suggested solutions from here or here.

Solution 4

I had the same error in visual studio 2019.

Problem could be fixed by:

  • Close Visual Studio
  • Delete '.vs' directory
  • Open Project
  • Rebuild

Solution 5

All the answers above didn't work for me.

However, this is the Error message i got -
"detected package version outside of dependency constraint microsoft.aspnetcore.app 2.1.1 requires microsoft.netcore.razor.design...bla bla bla"

How i overcame it was to install a lower version of razor via nuget package manager:

Steps:

on Visual Studio 2017 Click on Tools > Nuget Package Manager > Package Manager Console then run the command below.

Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design -Version 2.1.1

Share:
13,368
Patrick Christensen
Author by

Patrick Christensen

Updated on June 06, 2022

Comments

  • Patrick Christensen
    Patrick Christensen almost 2 years

    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 error I'm getting is the following:

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

    It's consistant everytime I try to create a new element. Earlier, I bypassed the error by copying a view and repurposing it. But that's not optimal in the long run!

    I'm currently sitting at work doing this tutorial where the issues arise. However, when I started this tutorial at home yesterday (hence, on a different network) I had zero issues. Might that have something to say?

    Here's a link to the project on GitHub.

    Do you think it's an issues with my network, my project itself, or something completely different?

  • Patrick Christensen
    Patrick Christensen over 6 years
    I tried clearing the cache you mentioned -- No dice! Another user, Miklós, commented that it might be an install issue, so I'm currently uninstalling VS. :) Thanks for the suggestion!
  • Matt Stannett
    Matt Stannett about 6 years
    @PatrickChristensen edited my answer to include some more suggestions.
  • mini998
    mini998 about 6 years
    This worked for me thanks. I had to clean C:\Users\xxxxx\AppData\Local\Microsoft\VisualStudio\15.0_24f‌​d3914 for VS 2017 ( where xxxxx is your user account name)
  • s k
    s k about 6 years
    I had renamed the folder mentioned by mini998, starts VS2017. It will creates a new folder with similar name. Delete the new folder, then replace with the original one. And the problem is fixed automagically.
  • James Toomey
    James Toomey almost 6 years
    Running dotnet restore in Tools>Nuget Package Manager>Package Manager Console fixed this for me.
  • Pajri Aprilio
    Pajri Aprilio over 5 years
    it worked for me. but need to rebuild solution after dot net restore. thanks
  • hackingchemist
    hackingchemist over 4 years
    Thanks! This was the solution for me as the other suggestions didn't work. Opening a visual studio 2017 project in 2019 was causing the error when I tried adding a controller.
  • shubhamr
    shubhamr about 2 years
    Thank you so much ! Was scratching my head for hours and this really helped me.