dotnet / dotnet/roslyn

Can't move type to file due to `MoveTypeCodeRefactoringProvider` error

Open
#75,405 2 comments 0 reactions 0 assignees View on GitHub
Area-IDE
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**: 17.12 P2.1 with .NET 8 project (8.0.108 SDK)

**Stack trace**:

```
Microsoft.Assumes+InternalErrorException : Did not find new element in the hierarchy for item "REDACTED.cs". The item would have been added with type "Compile". The project item schema service knows about this item type. The item does not exist in the project file.
at Microsoft.Assumes.Fail(String message)
at async Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProjectItems.EvaluateAddResultAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProjectItems.AddItemAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.AddDocumentToProjectItems(ProjectItems projectItems,DocumentId documentId,String folderPath,String documentName,SourceText initialText,String filePath,TextDocumentKind documentKind)
at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.AddDocumentToFolder(Project project,DocumentId documentId,IEnumerable`1 folders,String documentName,TextDocumentKind documentKind,SourceText initialText,String filePath)
at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.AddDocumentCore(DocumentInfo info,SourceText initialText,TextDocumentKind documentKind)
at Microsoft.CodeAnalysis.Workspace.ApplyProjectChanges(ProjectChanges projectChanges)
at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution,IProgress`1 progressTracker)
at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.TryApplyChanges(Solution newSolution,IProgress`1 progressTracker)
at Microsoft.CodeAnalysis.CodeActions.ApplyChangesOperation.ApplyOrMergeChanges(Workspace workspace,Solution originalSolution,Solution changedSolution,IProgress`1 progressTracker,CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CodeActions.ApplyChangesOperation.TryApplyAsync(Workspace workspace,Solution originalSolution,IProgress`1 progressTracker,CancellationToken cancellationToken)
at async Microsoft.CodeAnalysis.CodeActions.CodeActionEditHandlerService.ProcessOperationsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeActionEditHandlerService.ApplyAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.InvokeWorkerAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformActionAsync()
```

(May be related to recent Create & Copy File issues in VS?)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the MoveTypeCodeRefactoringProvider failure in the reported Visual Studio 17.12 P2.1 .NET 8 setup, then trace the AddDocumentToProjectItems and AddDocumentToFolder entry points in VisualStudioWorkspaceImpl. Compare the behavior with the referenced Create and Copy File issues; done means moving a type to a file completes without the reported project-item hierarchy exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.