roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

"Unexpected Null" dialog (and consequences) in Visual Studio when using Refactor, Extract Method

Open leppie opened this issue 10 years ago • 35 comments

Repro in VS2015 Update 1 (not sure if others are affected):

In src\Compilers\CSharp\Portable\Binder\Binder_Symbols.cs, add the following on line 1835:

void Foo(

Now select the ternary expression just above it (between return and ;). Do Refactor, Extract Method.

An error dialog appears, stating 'Unexpected Null'.

image

Close the dialog, and open another a file. This file's editor is now seemingly readonly (till you close and re-open again).

Not sure if this is caused by Roslyn.

leppie avatar Dec 09 '15 15:12 leppie

Closing, cant repro after restarting VS.

leppie avatar Dec 09 '15 16:12 leppie

I get this all the time. It seems to happen only when the code is in a broken state. Once this does happen, only a VS restart will fix it.. I will try and nail down a concrete reproduction.

Camuvingian avatar May 25 '16 10:05 Camuvingian

Seconded.

Appears to occur when you have the code in a broken state. Even if fixing the compilation error prior to doing the rename, this often occurs as a result. Difficult to say if the 'previous bad state' is a principle cause though.

This also frequently occurs on Refactor Rename.

AlexanderMorou avatar Aug 11 '16 15:08 AlexanderMorou

I can close the solution and re-open the solution and get it working again.

toddmo avatar Aug 29 '16 18:08 toddmo

Same thing is happening to me. I'm using the following version of Visual Studio:

Microsoft Visual Studio Community 2015 Version 14.0.25431.01 Update 3

luisperezphd avatar Nov 06 '16 16:11 luisperezphd

Same here. Visual Studio Professional 2015 Version 14.0.25431.01 Update 3

charint0 avatar Nov 15 '16 16:11 charint0

Some more details, don't know if this helps...

Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 3

Opened a WinForms control designer, started changing some lambda expressions in the codebehind - at that point, the intellisense was already starting to act strangely (probably not working at all). I pressed F2 to rename a variable that was in non-lambda procedural code. Got the "Unexpected null" dialog. I managed to catch the original exception that results in this dialog, see the stack trace below. When I closed the codebehind file and reopened it, I got the file as read-only. But - when I closed both the winforms designer and the codebehind file and opened the codebehind, it resumed working... So no need to restart VS this time.

Here's the stack trace:

Microsoft.CodeAnalysis.Workspaces.dll!Roslyn.Utilities.Contract.ThrowIfNull<System.__Canon>(System.__Canon value, string message) Unknown Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.InitializeOpenBuffers(Microsoft.VisualStudio.Text.SnapshotSpan triggerSpan) Unknown Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.InlineRenameSession(Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameService renameService, Microsoft.CodeAnalysis.Workspace workspace, Microsoft.VisualStudio.Text.SnapshotSpan triggerSpan, Microsoft.CodeAnalysis.Editor.IInlineRenameInfo renameInfo, Microsoft.CodeAnalysis.Editor.Host.IWaitIndicator waitIndicator, Microsoft.CodeAnalysis.Editor.ITextBufferAssociatedViewService textBufferAssociatedViewService, Microsoft.VisualStudio.Text.ITextBufferFactoryService textBufferFactoryService, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.Editor.IRefactorNotifyService> refactorNotifyServices, Microsoft.CodeAnalysis.Shared.TestHooks.IAsynchronousOperationListener asyncListener) Unknown Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameService.StartInlineSession(Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.TextSpan textSpan, System.Threading.CancellationToken cancellationToken) Unknown Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.RenameCommandHandler.ExecuteRenameWorker(Microsoft.CodeAnalysis.Editor.Commands.RenameCommandArgs args, System.Threading.CancellationToken cancellationToken) Unknown Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.RenameCommandHandler.ExecuteCommand.AnonymousMethod__0(Microsoft.CodeAnalysis.Editor.Host.IWaitContext waitContext) Unknown Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.VisualStudioWaitIndicator.Wait(string title, string message, bool allowCancel, bool showProgress, System.Action<Microsoft.CodeAnalysis.Editor.Host.IWaitContext> action) Unknown Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.RenameCommandHandler.ExecuteCommand(Microsoft.CodeAnalysis.Editor.Commands.RenameCommandArgs args, System.Action nextHandler) Unknown Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.Commands.CommandHandlerService.ExecuteHandlers<Microsoft.CodeAnalysis.Editor.Commands.RenameCommandArgs>(System.Collections.Generic.IList<Microsoft.CodeAnalysis.Editor.ICommandHandler<Microsoft.CodeAnalysis.Editor.Commands.RenameCommandArgs>> commandHandlers, Microsoft.CodeAnalysis.Editor.Commands.RenameCommandArgs args, System.Action lastHandler) Unknown Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.Commands.CommandHandlerService.Execute<Microsoft.CodeAnalysis.Editor.Commands.RenameCommandArgs>(Microsoft.VisualStudio.Utilities.IContentType contentType, Microsoft.CodeAnalysis.Editor.Commands.RenameCommandArgs args, System.Action lastHandler) Unknown Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.AbstractOleCommandTarget.ExecuteRename(Microsoft.VisualStudio.Text.ITextBuffer subjectBuffer, Microsoft.VisualStudio.Utilities.IContentType contentType, System.Action executeNextCommandTarget) Unknown Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.AbstractOleCommandTarget.ExecuteVisualStudio2000(ref System.Guid pguidCmdGroup, uint commandId, uint executeInformation, System.IntPtr pvaIn, System.IntPtr pvaOut, Microsoft.VisualStudio.Text.ITextBuffer subjectBuffer, Microsoft.VisualStudio.Utilities.IContentType contentType) Unknown Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.AbstractOleCommandTarget.Exec(ref System.Guid pguidCmdGroup, uint commandId, uint executeInformation, System.IntPtr pvaIn, System.IntPtr pvaOut) Unknown Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.CommandChainNode.InnerExec(ref System.Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, System.IntPtr pvaIn, System.IntPtr pvaOut) Unknown Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.Exec(ref System.Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, System.IntPtr pvaIn, System.IntPtr pvaOut) Unknown Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.CompoundTextViewWindow.Exec(ref System.Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, System.IntPtr pvaIn, System.IntPtr pvaOut) Unknown Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.DocumentObjectSite.Exec(ref System.Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, System.IntPtr pvaIn, System.IntPtr pvaOut) Unknown Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.Exec(ref System.Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, System.IntPtr pvaIn, System.IntPtr pvaOut) Unknown

bdrajer avatar Feb 16 '17 16:02 bdrajer

@dpoeschl can you take a look here?

Pilchie avatar Feb 16 '17 17:02 Pilchie

Happened for me when trying refactor - rename on a local function (winforms app, currently in a non-compiling state). Had to restart to fix (making it compile without a restart didn't fix).

SimonSDA avatar Mar 29 '17 09:03 SimonSDA

+1 Irritating as hell.

alexmcmillan avatar Apr 05 '17 23:04 alexmcmillan

I have gotten this error in VS 2015 Enterprise and now in VS 2017 Enterprise. It appears to be after other changes have been made to the code. Exiting and restarting VS resolves the issue but it should be fixed.

dmhitchner avatar Jun 02 '17 12:06 dmhitchner

Also reported in https://developercommunity.visualstudio.com/content/problem/65044/refactoring-tool-rename-fails.html.

Pilchie avatar Jun 06 '17 15:06 Pilchie

Mondo escrow triage: keeping this in 15.3, given the number of reports.

MattGertz avatar Jun 30 '17 20:06 MattGertz

+1 for VS 15.2 (26430.15). Same as above: break seems to be related to non-compiling intermediate code-state, reboot fixes. Not noted above: workaround editing the name and then using "Show potential fixes" (Ctrl-.) and selecting "rename 'old' to 'new'" keeps working.

marcrocny avatar Jul 14 '17 12:07 marcrocny

+1

clefranc avatar Jul 16 '17 11:07 clefranc

1

lindexi avatar Jul 16 '17 13:07 lindexi

+1 happens all the time. Only vs restart will work

noam-honig avatar Jul 25 '17 05:07 noam-honig

+1 Started happening to me this morning. Has happened 4 times now and need to restart VS each time to fix it.

Arjailer avatar Jul 26 '17 10:07 Arjailer

Also in https://developercommunity.visualstudio.com/content/problem/85778/unexpected-null-when-trying-to-rename-a-variable.html

Pilchie avatar Jul 27 '17 21:07 Pilchie

It happens also occasionally for me. Renaming in C# with <Ctrl+R><Ctrl+R> fails. Renaming by overtyping a new name and then select refactor - rename works though.

GerardFZ avatar Aug 07 '17 15:08 GerardFZ