Skip to content

CSharpEditAndContinueAnalyzer.ClassifyUpdate of VariableDeclaratorSyntax. Cast exception on (TypeDeclarationSyntax)oldNode.Parent.Parent.Parent; #32889

@ivanbasov

Description

@ivanbasov

Callstack reported:

System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.EventFieldDeclarationSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax'.
   at Microsoft.CodeAnalysis.CSharp.EditAndContinue.CSharpEditAndContinueAnalyzer.EditClassifier.ClassifyUpdate(VariableDeclaratorSyntax oldNode, VariableDeclaratorSyntax newNode)
   at Microsoft.CodeAnalysis.CSharp.EditAndContinue.CSharpEditAndContinueAnalyzer.EditClassifier.ClassifyUpdate(SyntaxNode oldNode, SyntaxNode newNode)
   at Microsoft.CodeAnalysis.CSharp.EditAndContinue.CSharpEditAndContinueAnalyzer.EditClassifier.ClassifyEdit()
   at Microsoft.CodeAnalysis.CSharp.EditAndContinue.CSharpEditAndContinueAnalyzer.ReportSyntacticRudeEdits(List`1 diagnostics, Match`1 match, Edit`1 edit, Dictionary`2 editMap)
   at Microsoft.CodeAnalysis.EditAndContinue.AbstractEditAndContinueAnalyzer.AnalyzeSyntax(EditScript`1 script, Dictionary`2 editMap, SourceText oldText, SourceText newText, DocumentId documentId, IActiveStatementTrackingService trackingService, ImmutableArray`1 oldActiveStatements, ActiveStatement[] newActiveStatements, ImmutableArray`1[] newExceptionRegions, List`1 updatedMethods, List`1 diagnostics)
   at Microsoft.CodeAnalysis.EditAndContinue.AbstractEditAndContinueAnalyzer.<AnalyzeDocumentAsync>d__65.MoveNext()
…

It seems that
http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp.Features/EditAndContinue/CSharpEditAndContinueAnalyzer.cs,2491
should be changed from
var fieldDeclaration = (FieldDeclarationSyntax)oldNode.Parent.Parent;
to
var fieldDeclaration = (BaseFieldDeclarationSyntax)oldNode.Parent.Parent;

We should add a unit test for this as well.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions