Skip to content

Tab to insert new method for event handler crashed with top-level statements #49325

@PathogenDavid

Description

@PathogenDavid

Version Used: Compiler version: '3.9.0-1.20521.14 (182c1e3)'. Language version: 9.0.

Steps to Reproduce:

With the cursor at the location of $$ below, type +=

using System;

AppDomain.CurrentDomain.AssemblyResolve $$

Visual Studio will offer to create a method for event handler:

image

Press tab to accept adding the new method.

Expected Behavior: A local function is created for the event handler.

Actual Behavior: A NullReferenceException is thrown:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CodeGeneration.CodeGenerator.AddMethodDeclaration[TDeclarationNode](TDeclarationNode destination, IMethodSymbol method, Workspace workspace, CodeGenerationOptions options)
   at Microsoft.CodeAnalysis.Editor.CSharp.EventHookup.EventHookupCommandHandler.AddGeneratedHandlerMethodToSolution(SemanticDocument document, String eventHandlerMethodName, SyntaxAnnotation plusEqualsTokenAnnotation, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Editor.CSharp.EventHookup.EventHookupCommandHandler.CreateSolutionWithEventHandler(Document document, String eventHandlerMethodName, Int32 position, Int32& plusEqualTokenEndPosition, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Editor.CSharp.EventHookup.EventHookupCommandHandler.GenerateAndAddEventHandler(ITextView textView, ITextBuffer subjectBuffer, String eventHandlerMethodName, Action nextHandler, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Editor.CSharp.EventHookup.EventHookupCommandHandler.HandleTabWorker(ITextView textView, ITextBuffer subjectBuffer, Action nextHandler, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Editor.CSharp.EventHookup.EventHookupCommandHandler.ExecuteCommand(TabKeyCommandArgs args, Action nextHandler, CommandExecutionContext cotext)
   at Microsoft.VisualStudio.UI.Text.Commanding.Implementation.EditorCommandHandlerService.<>c__DisplayClass14_1`1.<ExecuteStartingAtIndex>b__0()
   at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(Object errorSource, Action call, Predicate`1 exceptionFilter)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Maybe related, but not quite the same: #44425 #44387 #43878

Metadata

Metadata

Assignees

Labels

Area-IDEBughelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions