Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
leppie opened this issue Dec 9, 2015 · 35 comments

Comments

@leppie
Copy link
Contributor

commented Dec 9, 2015

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

This comment has been minimized.

Copy link
Contributor Author

commented Dec 9, 2015

Closing, cant repro after restarting VS.

@Camuvingian

This comment has been minimized.

Copy link

commented May 25, 2016

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.

@AlexanderMorou

This comment has been minimized.

Copy link

commented Aug 11, 2016

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.

@toddmo

This comment has been minimized.

Copy link

commented Aug 29, 2016

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

@luisperezphd

This comment has been minimized.

Copy link

commented Nov 6, 2016

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

@charint0

This comment has been minimized.

Copy link

commented Nov 15, 2016

Same here.
Visual Studio Professional 2015
Version 14.0.25431.01 Update 3

@bdrajer

This comment has been minimized.

Copy link

commented Feb 16, 2017

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

@Pilchie Pilchie reopened this Feb 16, 2017

@Pilchie

This comment has been minimized.

Copy link
Member

commented Feb 16, 2017

@dpoeschl can you take a look here?

@Pilchie Pilchie added this to the 15.1 milestone Feb 16, 2017

@Pilchie Pilchie modified the milestones: 2.1, 15.1, 15.3 Mar 8, 2017

@SimonSDA

This comment has been minimized.

Copy link

commented Mar 29, 2017

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

@alexmcmillan

This comment has been minimized.

Copy link

commented Apr 5, 2017

+1 Irritating as hell.

@dmhitchner

This comment has been minimized.

Copy link

commented Jun 2, 2017

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.

@Pilchie

This comment has been minimized.

@MattGertz

This comment has been minimized.

Copy link
Contributor

commented Jun 30, 2017

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

@marcrocny

This comment has been minimized.

Copy link

commented Jul 14, 2017

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

@clefranc

This comment has been minimized.

Copy link

commented Jul 16, 2017

+1

@dpoeschl dpoeschl modified the milestones: 15.4, 15.7 Oct 20, 2017

@DJacquard

This comment has been minimized.

Copy link

commented Oct 25, 2017

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.

@sheinema

This comment has been minimized.

Copy link

commented Nov 7, 2017

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

@ak98

This comment has been minimized.

Copy link

commented Nov 19, 2017

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.

@waswat

This comment has been minimized.

Copy link

commented Nov 20, 2017

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.

@duncanawoods

This comment has been minimized.

Copy link

commented Nov 25, 2017

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.

@jeubank12

This comment has been minimized.

Copy link

commented Nov 29, 2017

15.4.5 on Ctrl+R,Ctrl+R

Restarted VS and no issues.

@ketcher-c

This comment has been minimized.

Copy link

commented Nov 30, 2017

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.

@jinujoseph jinujoseph modified the milestones: 15.7, 15.6 Dec 21, 2017

@jinujoseph

This comment has been minimized.

@waswat

This comment has been minimized.

Copy link

commented Dec 22, 2017

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

@themightylc

This comment has been minimized.

Copy link

commented Feb 13, 2018

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.

jinujoseph added a commit that referenced this issue Feb 14, 2018

Add null check for textSnapshot (#24693)
* Add null check for textSnapshot

Fixes #7364

* Respond to feedback

Changed from return to continue and added a non fatal exception

* respond to feedback

Moved NullTextBufferException to InlineRenameSession and added SourceText.
@jinujoseph

This comment has been minimized.

Copy link
Contributor

commented Feb 14, 2018

Fix available in 15.6. Preview6 +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.