Exception on trying to rename a type in shared projects
Visual Studio Version: Latest 16.6 dogfood build
Summary: Exception on attempting to rename a type in shared project
Steps to Reproduce:
-
Sync to latest Roslyn master sources, https://github.com/dotnet/roslyn/commit/d511d2656df15054826fcf8bb88bd5758188cb62 at the time of opening this issue.
-
Run
restorefrom root of the repo and open Roslyn.sln -
Attempt to rename a type in shared project, say FileHeader. This repros with any type in shared projects in Roslyn.sln.
Expected Behavior: Rename succeeds
Actual Behavior: Rename fails with the following exception. Once it crashed VS and other time it showed a goldbar with the exception.
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at Microsoft.VisualStudio.ProjectSystem.Designers.UnattachedProjectTreeNode.Find(IntPtr nodeId)at Microsoft.VisualStudio.ProjectSystem.Designers.ProjectTree.Find(IntPtr nodeId)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.ProjectNode.GetProjectTreeById(IntPtr nodeIdentity)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.SimpleHierarchyNode.get_TreeNode()
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.SimpleItemNode.get_IsBrowseObjectHidden()
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.SimpleItemNode.GetNodeProperties()
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProperties.Create(Object parent, SimpleHierarchyNode hierarchyNode)
at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProjectItem.get_Properties()
at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.Extensions.ProjectItemExtensions.TryGetFullPath(ProjectItem item, String& fullPath)
at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.ApplyDocumentInfoChanged(DocumentId documentId, DocumentInfo updatedInfo)
at Microsoft.CodeAnalysis.Workspace.ApplyChangedDocument(ProjectChanges projectChanges, DocumentId documentId)
at Microsoft.CodeAnalysis.Workspace.ApplyProjectChanges(ProjectChanges projectChanges)
at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker)
at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker)
at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution)
at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.ApplyRename(Solution newSolution, IWaitContext waitContext)
at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitCore(IWaitContext waitContext, Boolean previewChanges)
at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.<>c__DisplayClass78_0.<CommitWorker>b__0(IWaitContext waitContext)
at Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.VisualStudioWaitIndicator.Wait(String title, String message, Boolean allowCancel, Boolean showProgress, Action`1 action)
at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitWorker(Boolean previewChanges)
at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.RenameCommandHandler.ExecuteCommand(ReturnKeyCommandArgs args, CommandExecutionContext context)
at Microsoft.VisualStudio.Commanding.CommandHandlerExtensions.ExecuteCommand[T](ICommandHandler commandHandler, T args, Action nextCommandHandler, CommandExecutionContext executionContext)
at Microsoft.VisualStudio.UI.Text.Commanding.Implementation.EditorCommandHandlerService.<>c__DisplayClass14_1`1.<Execute>b__1()
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)
@ocallesp please take a look and see whether this should be moved to CPS.
This one was incredibly confusing when I hit it. If you initiate the rename at the class declaration, it looks like the rename failed completely since there are no obvious changes, and yet you now have errors in other projects telling you the old name no longer exists.
In actual fact, the rename of the declaration succeeded, but no references were updated, and the file you're still looking at is no longer part of the project (and will be hidden in the solution explorer if "Show all files" is not enabled). The only indication in the editor of what's happend, is the project context drop-down changes to "Miscellaneous".
Also, this only seems to happen when "Rename symbol's file" is enabled.
Does not repro.
Based on the stack provided, this is in the Cps layer.

But there are other issues like performance, and sometimes it does not apply type rename when selecting "Rename Symbol's file".
@ocallesp This still happens for me in the just-released 17.4.0. The gold bar is no longer shown, but the shared project is still broken as I described in #8306, and if you attach a debugger to devenv.exe, you can still see the KeyNotFoundException exception:
> Microsoft.VisualStudio.ProjectSystem.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.Designers.UnattachedProjectTreeNode.Find(System.IntPtr nodeId) Unknown
Microsoft.VisualStudio.ProjectSystem.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.Designers.ProjectTree.Find(System.IntPtr nodeId) Unknown
Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.ProjectNode.GetProjectTreeById(System.IntPtr nodeIdentity) Unknown
Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.SimpleItemNode.IsBrowseObjectHidden.get() Unknown
Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.SimpleItemNode.GetNodeProperties() Unknown
Microsoft.VisualStudio.ProjectSystem.VS.Implementation.dll!Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProperties.Create(object parent, Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.SimpleHierarchyNode hierarchyNode) Unknown
Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.Extensions.ProjectItemExtensions.TryGetFullPath(EnvDTE.ProjectItem item, out string fullPath) Unknown
Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.ApplyDocumentInfoChanged(Microsoft.CodeAnalysis.DocumentId documentId, Microsoft.CodeAnalysis.DocumentInfo updatedInfo) Unknown
Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.ApplyChangedDocument(Microsoft.CodeAnalysis.ProjectChanges projectChanges, Microsoft.CodeAnalysis.DocumentId documentId) Unknown
Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.ApplyProjectChanges(Microsoft.CodeAnalysis.ProjectChanges projectChanges) Unknown
Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Microsoft.CodeAnalysis.Solution newSolution, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker progressTracker) Unknown
Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.TryApplyChanges(Microsoft.CodeAnalysis.Solution newSolution, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker progressTracker) Unknown
Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.TryApplyRenameAsync(Microsoft.CodeAnalysis.Solution newSolution, System.Threading.CancellationToken cancellationToken) Unknown
[Resuming Async Method]
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 980 C#
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 928 C#
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run() Line 1070 C#
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0() Line 977 C#
Microsoft.VisualStudio.Threading.dll!Microsoft.VisualStudio.Threading.JoinableTaskFactory.SingleExecuteProtector.TryExecute() Unknown
Microsoft.VisualStudio.Threading.dll!Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread() Unknown
Microsoft.VisualStudio.Threading.dll!Microsoft.VisualStudio.Threading.JoinableTask<bool>.CompleteOnCurrentThread() Unknown
Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitWorker(bool previewChanges) Unknown
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.RenameFlyoutViewModel.Submit() Unknown
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Unknown
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) Unknown
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) Unknown
PresentationCore.dll!System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawKeyboardActions actions, int scanCode, bool isExtendedKey, bool isSystemKey, int virtualKey) Unknown
PresentationCore.dll!System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(ref System.Windows.Interop.MSG msg, ref bool handled) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(ref System.Windows.Interop.MSG msg, System.Windows.Input.ModifierKeys modifiers) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.OnPreprocessMessage(object param) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(ref System.Windows.Interop.MSG msg, ref bool handled) Unknown
WindowsBase.dll!System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(ref System.Windows.Interop.MSG msg) Unknown
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.RenameFlyoutViewModel.OnPreTranslateMessage(object sender, Microsoft.VisualStudio.PlatformUI.OleComponentSupport.PreTranslateMessageEventArgs e) Unknown
Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.PlatformUI.OleComponentSupport.OleComponent.FPreTranslateMessageCore(Microsoft.VisualStudio.OLE.Interop.MSG[] pMsg) Unknown
Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.PlatformUI.OleComponentSupport.OleComponent.Microsoft.VisualStudio.OLE.Interop.IOleComponent.FPreTranslateMessage.AnonymousMethod__0() Unknown
Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.PlatformUI.OleComponentSupport.OleComponent.CallAndReturnOnException(System.Func<int> method, int retValueOnException) Unknown
[Async Call Stack]
[Async] Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitCoreAsync.AnonymousMethod__0() Unknown
[Async] Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.DismissUIAndRollbackEditsAndEndRenameSessionAsync(Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.RenameLogMessage.UserActionOutcome outcome, bool previewChanges, System.Func<System.Threading.Tasks.Task> finalCommitAction) Unknown
[Async] Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitCoreAsync(Microsoft.VisualStudio.Utilities.IUIThreadOperationContext operationContext, bool previewChanges) Unknown
[Async] Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitWorkerAsync(bool previewChanges, bool canUseBackgroundWorkIndicator, System.Threading.CancellationToken cancellationToken) Unknown
[Async] Microsoft.VisualStudio.Threading.dll!Microsoft.VisualStudio.Threading.JoinableTask.SetWrappedTask.AnonymousMethod__88_0(System.Threading.Tasks.Task t, object s) Unknown
Can you please re-open the issue so someone can investigate?
Re-opening and sending back to triage.
This should be moved to CPS.
Moved to CPS AB#1676845