Skip to content

Fix invalid workspace state when decompilation cancelled.#80643

Merged
dibarbet merged 3 commits intodotnet:release/dev18.0from
dibarbet:fix_decompilation
Oct 13, 2025
Merged

Fix invalid workspace state when decompilation cancelled.#80643
dibarbet merged 3 commits intodotnet:release/dev18.0from
dibarbet:fix_decompilation

Conversation

@dibarbet
Copy link
Member

@dibarbet dibarbet commented Oct 10, 2025

Resolves #80329

Was able to reproduce and verify locally with a task.delay inserted.

@dibarbet dibarbet requested a review from a team as a code owner October 10, 2025 20:49
var (temporaryProjectInfo, temporaryDocumentId) = GenerateProjectAndDocumentInfo(fileInfo, metadataWorkspace.CurrentSolution.Services, sourceProject, topLevelNamedType);
metadataWorkspace.OnProjectAdded(temporaryProjectInfo);
var temporaryDocument = metadataWorkspace.CurrentSolution
var temporarySolution = metadataWorkspace.CurrentSolution.AddProject(temporaryProjectInfo);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@dibarbet
Copy link
Member Author

/backport to main

@github-actions
Copy link
Contributor

Started backporting to main: https://github.com/dotnet/roslyn/actions/runs/18419495091

@dibarbet
Copy link
Member Author

/backport to main

@github-actions
Copy link
Contributor

Started backporting to main: https://github.com/dotnet/roslyn/actions/runs/18421182416

@dibarbet dibarbet mentioned this pull request Oct 11, 2025
@dibarbet dibarbet merged commit 7463b65 into dotnet:release/dev18.0 Oct 13, 2025
25 checks passed
@dibarbet dibarbet deleted the fix_decompilation branch October 13, 2025 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants