"Unexpected Null" dialog (and consequences) in Visual Studio when using Refactor, Extract Method
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'.

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.
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>(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
@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.
Also reported in https://developercommunity.visualstudio.com/content/problem/65044/refactoring-tool-rename-fails.html.
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.
Also in https://developercommunity.visualstudio.com/content/problem/85778/unexpected-null-when-trying-to-rename-a-variable.html
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.