Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NFW due to invoking Workspace.RaiseEventForHandlers in the CA process #77546

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Workspaces/Core/Portable/Workspace/Workspace_Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ protected Task RaiseWorkspaceChangedEventAsync(WorkspaceChangeKind kind, Solutio
projectId = documentId.ProjectId;
}

var args = new WorkspaceChangeEventArgs(kind, oldSolution, newSolution, projectId, documentId);
Copy link
Member

Choose a reason for hiding this comment

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

is saving making the args worth it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not a huge difference, but the creation of those args caused a separate issue for another team's test that called this with a null oldSolution. We had them changed that, but only creating the args when necessary would have avoided the issue for them. And this is actually how I had originally coded this up before code reviews for the original change, so I thought it best to go back to something I had tested more thoroughly.


WorkspaceChangeEventArgs args = null;
var ev = GetEventHandlers<WorkspaceChangeEventArgs>(WorkspaceChangedImmediateEventName);
RaiseEventForHandlers(ev, args, FunctionId.Workspace_EventsImmediate);

if (ev.HasHandlers)
{
args = new WorkspaceChangeEventArgs(kind, oldSolution, newSolution, projectId, documentId);
RaiseEventForHandlers(ev, args, FunctionId.Workspace_EventsImmediate);
}

ev = GetEventHandlers<WorkspaceChangeEventArgs>(WorkspaceChangeEventName);
if (ev.HasHandlers)
{
args ??= new WorkspaceChangeEventArgs(kind, oldSolution, newSolution, projectId, documentId);
return this.ScheduleTask(() =>
{
RaiseEventForHandlers(ev, args, FunctionId.Workspace_Events);
Expand Down
Loading