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

Created on 9 Dec 2015  路  35Comments  路  Source: dotnet/roslyn

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.

Area-IDE Bug Developer Community Resolution-Fixed _Product-level triaged

Most helpful comment

+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.

All 35 comments

Closing, cant repro after restarting VS.

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.

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.

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

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

Same here.
Visual Studio Professional 2015
Version 14.0.25431.01 Update 3

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 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 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 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(System.Collections.Generic.IList> commandHandlers, Microsoft.CodeAnalysis.Editor.Commands.RenameCommandArgs args, System.Action lastHandler) Unknown
Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.Commands.CommandHandlerService.Execute(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

@dpoeschl can you take a look here?

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).

+1 Irritating as hell.

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.

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

+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.

+1

1

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

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

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

For my workflow, this is the second most annoying bug in VS2015. It happens frequently.

image

image
Same problem when renaming a variable. Happened more than twice.
I knew it could be fixed if I restarted VS but it's obviously a bug.

That last submission on Developer Community was mine. In answer to your comment, paradoxically I can't give you steps for repro or a solution that exhibits the problem though it does happen to me reliably. By reliably I mean it will fail precisely when I need to use it in a real-world work situation but never when I'm testing to see if it the function is broken.

+1 v15.4.2, happens consistently several times per day, VS restart required.

Getting the Unexpected null error now. After installing DevExpress CodeRush. Error goes away when the CodeRush Extension is disabled.
snip_20171120000024
Then when CodeRush Reenabled but not the IntelliRush component all is working.

Same issue in 15.4.4 when using f2 to rename variables

devenv_2017-11-20_13-52-52

Might have something to do with going into sleep mode and returning from that?

Works fine after restarting VS.

Getting this multiple times a day - 15.4.2.

Large .net core project, fresh install. Have to restart visual studio.

Also get the IDE exiting rename mode by itself while typing.

15.4.5 on Ctrl+R,Ctrl+R

Restarted VS and no issues.

I'm getting this problem in VS 2017 15.4.5 when attempting to rename variables (F2 / Ctrl+R,Ctrl+R). Restarting Visual Studio does NOT solve the problem for me.

I'm using CodeRush for Roslyn. Disabling that extension is the only consistent way to regain F2 rename functionality. Rename capability occasionally returns while CodeRush is enabled, but it is never linked to a VS restart.

Ever since the latest update (15.5.2) I've been getting this error more frequently.

15.5.4 and up (15.5.6 now) has been the first ever occurrences of this error for me. It's quite frequent, actually.

Fix available in 15.6. Preview6 +

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gafter picture gafter  路  147Comments

mgravell picture mgravell  路  119Comments

stephentoub picture stephentoub  路  167Comments

MadsTorgersen picture MadsTorgersen  路  170Comments

gafter picture gafter  路  279Comments