C# "Failed to parse method 'InitializeComponent'. The parser reported the following error 'Invalid symbol kind: NamedType'"

Adam picture Adam · Aug 6, 2018 · Viewed 7.3k times · Source

I have a project written by someone else with .NET framework 4 I have a problem with one of the forms (others opening correctly).

When I try to open Form1 in "Design mode" Visual Studio 2017 shows the error screen and returns "Failed to parse method 'InitializeComponent'. The parser reported the following error 'Invalid symbol kind: NamedType'. Please look in the Task List for potential errors."

with Call Stack

at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(Object sender, EventArgs e)
at System.CodeDom.CodeMemberMethod.get_Statements()
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host) 

Answer

Will DP picture Will DP · Oct 8, 2018

To add to the body of knowledge, I was getting this same error. My situation was I was upgrading a solution created by JetBrains dotPeek. Its solution versioned as 10.0 (VS2008) and converted to 15.0 (VS2015) for VS2017, and is a .NET 3.5 target class library. After opening the form up (in the old style with no designer file) it always threw the error when opening the designer (but running the class library was fine). On carefully reviewing every line of InitializeComponent, I found a "this.Name = nameof(formname)". Looking at another form that worked, I saw "this.Name = "formname"". Once I changed the line over to the other approach, the designer opened perfectly!