Fix invalid workspace state when decompilation cancelled.#80643
Fix invalid workspace state when decompilation cancelled.#80643dibarbet merged 3 commits intodotnet:release/dev18.0from
Conversation
| var (temporaryProjectInfo, temporaryDocumentId) = GenerateProjectAndDocumentInfo(fileInfo, metadataWorkspace.CurrentSolution.Services, sourceProject, topLevelNamedType); | ||
| metadataWorkspace.OnProjectAdded(temporaryProjectInfo); | ||
| var temporaryDocument = metadataWorkspace.CurrentSolution | ||
| var temporarySolution = metadataWorkspace.CurrentSolution.AddProject(temporaryProjectInfo); |
There was a problem hiding this comment.
bug was here - we called OnProjectAdded, but if this got cancelled it never got added to the _generatedFilenameToInformation map. So we'd end up adding the same file path to the wrokspace multiple times, causing open to throw (when it tried to find a .Single document in the workspace with the path).
| temporaryDocument = metadataWorkspace.CurrentSolution.GetRequiredDocument(temporaryDocument.Id); | ||
|
|
||
| var newLoader = new WorkspaceFileTextLoader(temporaryDocument.Project.Solution.Services, fileInfo.TemporaryFilePath, MetadataAsSourceGeneratedFileInfo.Encoding); | ||
| metadataWorkspace.OnDocumentTextLoaderChanged(temporaryDocumentId, newLoader); |
There was a problem hiding this comment.
Can we easily update the text loader here with the real text before we call the OnProjectAdded? This is fine, not sure if we risk breaking something if/when a cancellation token were to get checked here again.
src/Features/Core/Portable/MetadataAsSource/DecompilationMetadataAsSourceFileProvider.cs
Show resolved
Hide resolved
80b332e to
1267367
Compare
|
/backport to main |
|
Started backporting to main: https://github.com/dotnet/roslyn/actions/runs/18419495091 |
src/Features/Core/Portable/MetadataAsSource/DecompilationMetadataAsSourceFileProvider.cs
Show resolved
Hide resolved
|
/backport to main |
|
Started backporting to main: https://github.com/dotnet/roslyn/actions/runs/18421182416 |
Resolves #80329
Was able to reproduce and verify locally with a task.delay inserted.