A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
Back up the project, then correct duplicate or mismatched control definitions in the affected form’s .Designer.vb file; this RoslynCodeDomService/Enumerable.Single stack trace is a WinForms Designer code-generation failure, not an array call-stack overflow.
Correct the designer file
This problem commonly appears after copying, renaming, or grouping controls into an array, when the generated designer code contains duplicate fields or inconsistent names.^1^
- Commit or copy the project before editing generated code.
- Close the affected form’s Designer tab.
- In Solution Explorer, select Show All Files if necessary.
- Expand the form and open
FormName.Designer.vb. - Search for each recently copied or renamed control. Every control should have:
- One field declaration.
- One construction statement in
InitializeComponent. - Consistent references in property assignments, event hookups, and container/array initialization.
- A unique
Namevalue.
For example, remove or correct inconsistencies such as:
Friend WithEvents Button1 As Button
Friend WithEvents Button1 As Button ' Duplicate: remove or rename
Private Sub InitializeComponent()
Me.Button2 = New Button()
Me.Button1.Name = "Button2" ' Mismatched reference/name
End Sub
Also verify that FormName.vb and FormName.Designer.vb declare the same partial-class name. Avoid changing unrelated generated code. The accepted resolution for the matching copy-and-rename failure is to correct stale names in declarations, initialization, property assignments, and Controls.Add statements.^2^
- Save the file.
- Select Build > Clean Solution, then Build > Rebuild Solution.
- Fix every compile error before reopening the form. The designer can fail because of errors in project code, generated code, or third-party components.^3^
If the definitions appear consistent
Clear generated state:
- Close Visual Studio completely.
- Delete the affected project’s
binandobjdirectories. - Optionally delete or rename the solution’s hidden
.vsdirectory. - Reopen Visual Studio and rebuild the solution.
- Open the form Designer again.
Deleting bin and obj is an official recovery step for stale designer/build artifacts.^3^
If it still fails
- Only one form fails: compare its
.vband.Designer.vbfiles with a newly created working form, especially the class name,Partial Class, inheritance, andInitializeComponent. - Many forms started failing together: update Visual Studio first; if the current update remains affected, run Visual Studio Installer > More > Repair.
- The project builds and no duplicate or mismatched definitions exist: report the reproducible designer failure through Help > Send Feedback > Report a Problem. Include the Visual Studio version, affected form files, stack trace, and a recording of the copy/rename operation if applicable.^4^
References