diff --git a/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs b/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs index 2aec192ec8b6d..a74ca6f544d62 100644 --- a/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs +++ b/src/Workspaces/Remote/ServiceHub/Host/RemoteWorkspace.SolutionCreator.cs @@ -575,23 +575,27 @@ private async Task UpdateDocumentInfoAsync(TextDocument document, // there is no api to change these once document is created Contract.ThrowIfFalse(document.State.Attributes.Id == newDocumentInfo.Id); - Contract.ThrowIfFalse(document.State.Attributes.Name == newDocumentInfo.Name); - Contract.ThrowIfFalse(document.State.Attributes.FilePath == newDocumentInfo.FilePath); Contract.ThrowIfFalse(document.State.Attributes.IsGenerated == newDocumentInfo.IsGenerated); Contract.ThrowIfFalse(document.State.Attributes.DesignTimeOnly == newDocumentInfo.DesignTimeOnly); + if (document.State.Attributes.Name != newDocumentInfo.Name) + document = document.Project.Solution.WithDocumentName(document.Id, newDocumentInfo.Name).GetRequiredDocument(document.Id); + + if (document.State.Attributes.FilePath != newDocumentInfo.FilePath) + document = document.Project.Solution.WithDocumentFilePath(document.Id, newDocumentInfo.FilePath).GetRequiredDocument(document.Id); + if (document.State.Attributes.Folders != newDocumentInfo.Folders) { // additional document can't change folder once created Contract.ThrowIfFalse(document is Document); - document = document.Project.Solution.WithDocumentFolders(document.Id, newDocumentInfo.Folders).GetDocument(document.Id)!; + document = document.Project.Solution.WithDocumentFolders(document.Id, newDocumentInfo.Folders).GetRequiredDocument(document.Id); } if (document.State.Attributes.SourceCodeKind != newDocumentInfo.SourceCodeKind) { // additional document can't change sourcecode kind once created Contract.ThrowIfFalse(document is Document); - document = document.Project.Solution.WithDocumentSourceCodeKind(document.Id, newDocumentInfo.SourceCodeKind).GetDocument(document.Id)!; + document = document.Project.Solution.WithDocumentSourceCodeKind(document.Id, newDocumentInfo.SourceCodeKind).GetRequiredDocument(document.Id); } return document;