Visual Studio Windows Form "Value does not fall within the expected range."
Asked Answered
A

3

6

In Visual Studio Enterprise 2017 when I create a Windows Form in my solution I get the following error page right away (instead of the designer page):

The stack trace is:

at Microsoft.VisualStudio.LanguageServices.CSharp.CodeModel.CSharpCodeModelService.GetTypeSymbolFromFullName(String fullName, Compilation compilation)
at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.RootCodeModel.DotNetNameFromLanguageSpecific(String languageName)
at EnvDTE80.CodeModel2.DotNetNameFromLanguageSpecific(String LanguageName)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.CodeTypeDeclarationFromCodeClass(CodeClass vsClass)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnNamespacePopulateTypes(Object sender, EventArgs e)
at System.CodeDom.CodeNamespace.get_Types()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.Parse(TextReader codeStream)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.MergedCodeDomParser.System.CodeDom.Compiler.ICodeParser.Parse(TextReader stream)
at System.CodeDom.Compiler.CodeDomProvider.Parse(TextReader codeStream)
at Microsoft.VisualStudio.Shell.Design.Serialization.CodeDom.CodeDomDocDataAdapter.get_CompileUnit()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)

The provided links on the page do not help since they only link to generic documentation/help pages. How can this error be fixed?

Ammonite answered 22/10, 2017 at 11:3 Comment(4)
Does this exception occur if you copy and paste an existing form?Dyal
Does github.com/Microsoft/VSProjectSystem/issues/177 help?Dyal
@mjwills: Similar, see my answer below.Ammonite
This is one of the frustrating and wide range error that might arise from VS messages to COM programming.Amenity
B
12

I got this in Visual Studio 2019 in a Windows Forms app. I'd been working on it for a few days, opening and closing the solution with no issue. I applied a VS upgrade and when I went to open the app, I got this error message.

When nothing else worked, I unloaded and reloaded the project from the solution, and that fixed it.

I hope it's as simple as that for you.

Bellerophon answered 23/7, 2021 at 1:21 Comment(0)
A
5

It turns out the folder was named Form and that clashed with the Microsoft Form class. Renaming the inherited class from Form to System.Windows.Forms.Form twice in total fixes the issue. Still a bug that should be handled automatically like this by Visual Studio.

Ammonite answered 22/10, 2017 at 15:16 Comment(0)
D
1

Different Problem same Error Message SOLVED ... "Value does not fall within the expected range" and designer not displaying my form.

SOLUTION: I had docked-to-Fill with a control to my main form, and it worked fine. But then I started getting the error, and the "designer" no longer displayed. I recently added a control from the Tool dialog with a double-click, instead of drag-and-drop ... that was the culprit. To fix it, I commented the line (in the myFormMain.Designer.cs) that docked the control to the main form. And yes, the designer view worked again and I could find and delete the control I added from the Tools dialog with a double-click.

Dielle answered 7/1, 2021 at 12:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.