Using Visual Studio 2026 (18.6.0) designer I keep getting Sequence contains no elements error when I add or change a control.

Doug Hahn 0 Reputation points
2026-05-24T14:35:48.0433333+00:00

Using Visual Studio 2026 (18.6.0) designer I keep getting "Sequence contains no elements" error when I add or change a control. It happens frequently and is quite annoying.

Developer technologies | Windows Forms
0 comments No comments

2 answers

Sort by: Most helpful
  1. Nancy Vo (WICLOUD CORPORATION) 8,155 Reputation points Microsoft External Staff Moderator
    2026-05-25T03:26:18.7733333+00:00

    Hello @Doug Hahn ,

    Thanks for your question.

    I want to check whether there are any warnings or errors related to Microsoft.VisualStudio.Web.CodeGeneration.Design. If yes, please show them to me.

    Furthermore, you can refer to these following workarounds:

    1. Please open the package manager sole by clicking:

    Tools -> Nuget Package Manager -> Package Manager Console.

    And then type:

    dotnet restore

    1. Close visual studio and then delete .vs directory -> Open project again and rebuild it.
    2. Please correct the names in designer file.
    • Do not rename multiple controls at once.
    • Instead of the Properties window, rename controls using F2 in code view — this triggers proper refactoring across all files.
    • If already broken, please fix Designer.cs manually:
      • Open YourForm.Designer.cs
      • Press Ctrl+H (Find & Replace, current document only)
      • Find the old name (for ex: textBox1)
      • Replace with new name (for ex: txtFirstName)
      • Also update the .Name = "string" line
      • Save → Rebuild

    Please try it and let me know if it works.

    I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.

    Was this answer helpful?


  2. AI answer

    2026-05-24T14:35:57.5566667+00:00

    Use the standard Windows Forms Designer troubleshooting steps first, since many intermittent designer errors are caused by stale build artifacts or bad resources rather than the controls themselves.

    1. Clean and rebuild the solution
      • In Solution Explorer, right‑click the solution (or the affected project) and select Clean.
      • Then right‑click again and select Rebuild.
      • This forces regeneration of designer metadata and often clears transient “Sequence contains no elements” errors that surface when adding or modifying controls.
    2. Delete bin/obj to clear cached artifacts
      • Close Visual Studio.
      • In File Explorer, go to the project folder.
      • Manually delete the bin and obj folders.
      • Reopen the solution in Visual Studio and build again. This can fix issues caused by corrupted temporary files or bad dependency state that the designer relies on.
    3. Check for bad .resx files (form resources) A corrupted or invalid .resx for the form’s default culture can cause designer parsing failures that show up as generic exceptions when editing controls.
      • In Solution Explorer, select Show All Files.
      • Locate the .resx file associated with the problematic form.
      • Right‑click the .resx file and choose Open → open it in the XML Editor.
      • Inspect and correct any obvious malformed XML or invalid entries, then save and rebuild.
    4. Use the designer error window details When the designer fails, use the yellow error bar:
      • Expand the error bar to see file, line, and column information.
      • Use the link to jump directly to the offending code in the .Designer.cs or code‑behind file.
      • Fix any syntax or initialization issues around the control being added/changed, then rebuild and reopen the designer.

    If the error persists after these steps, capture the full text from the designer error bar (including any call stack) and use Report a Problem in Visual Studio, as this may indicate a defect in the designer rather than in the form code.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.