Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

designer

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) 
like image 483
Adam Avatar asked Aug 06 '18 14:08

Adam


2 Answers

Go to InitializeComponent() function and search for nameof(). If found just replace value part to accurate value.

In my case it was

this.Text = nameof (Form1);

Changed to:

this.Text = "Page1";
like image 84
Ashish Gehlot Avatar answered Sep 19 '22 14:09

Ashish Gehlot


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!

like image 40
Will DP Avatar answered Sep 19 '22 14:09

Will DP