Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@davidwengier
Copy link
Member

Fixes microsoft/vscode-dotnettools#2629

I could not get a test working for this, I don't fully understand all of the machinery here. The Razor file was always coming back as a misc file even after being added to a real project?

var documents = miscWorkspace.CurrentSolution.GetDocumentIdsWithFilePath(documentPath);
if (documents.Any())
// Filter to actual documents, ignoring additional documents like Razor files etc.
var documentIds = solution.GetDocumentIdsWithFilePath(documentPath).WhereAsArray(id => solution.GetDocument(id) is not null);
Copy link
Member

Choose a reason for hiding this comment

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

im not sure this is quite right - razor docs are added as misc, and when we find the real one we need to remove the misc one. this will just cause it to leak.

might need to check below wjat kind of doc, and remove it

Copy link
Member Author

@davidwengier davidwengier Dec 22, 2025

Choose a reason for hiding this comment

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

Definitely not claiming to understand this, but the key change here in my mind is that this method not only doesn't error, but will now return false when it finds a Razor document. That allows the project system to fall back to the previous path and unload the misc project for the Razor file altogether.

It seems to me, from reading the code here, that since the CanonicalMiscFilesProjectLoader only ever adds documents, never additional documents, then it should only ever remove the same. Having said that, I don't know what "canonical" means in this scenario, nor why Razor files are ever seen in anything with "File Based" in the name.

What exactly does it mean to "leak" here?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry - I think you're right - the FBP loader will unload it if it returns false here. I missed that the FBP loader would actually do it if this returned false

var documents = miscWorkspace.CurrentSolution.GetDocumentIdsWithFilePath(documentPath);
if (documents.Any())
// Filter to actual documents, ignoring additional documents like Razor files etc.
var documentIds = solution.GetDocumentIdsWithFilePath(documentPath).WhereAsArray(id => solution.GetDocument(id) is not null);
Copy link
Member

Choose a reason for hiding this comment

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

Sorry - I think you're right - the FBP loader will unload it if it returns false here. I missed that the FBP loader would actually do it if this returned false

@davidwengier davidwengier merged commit 6e877c9 into dotnet:main Jan 6, 2026
27 checks passed
@davidwengier davidwengier deleted the DontAssumeDocument branch January 6, 2026 21:46
@davidwengier davidwengier restored the DontAssumeDocument branch January 6, 2026 21:46
@davidwengier davidwengier deleted the DontAssumeDocument branch January 6, 2026 21:47
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jan 6, 2026
@davidwengier davidwengier modified the milestones: Next, 18.4 Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intellisense getting crashed after viewing .razor file in file diff

2 participants