From ad27da7e6ce7215898b81fe4dd5cd886da7d35f5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 21:26:03 +0000 Subject: [PATCH 1/2] Initial plan From 1ebb35a894a3fb544ae441832022c86e34194198 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 21:31:56 +0000 Subject: [PATCH 2/2] Add comments explaining QueryStatus check and retry logic Co-authored-by: davidwengier <754264+davidwengier@users.noreply.github.com> --- .../InProcess/EditorInProcess_Commands.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Commands.cs b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Commands.cs index 3a07bdd5a02..25587647a35 100644 --- a/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Commands.cs +++ b/src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Commands.cs @@ -85,12 +85,17 @@ private async Task ExecuteCommandAsync(Guid commandGuid, uint commandId, Cancell var dispatcher = await TestServices.Shell.GetRequiredGlobalServiceAsync(cancellationToken); + // Set up the command structure to query the command's status var cmds = new OLECMD[1]; cmds[0].cmdID = commandId; cmds[0].cmdf = 0; + // Wait for the command to become enabled and supported before executing it. + // This prevents COM exceptions that can occur when trying to execute commands + // before they're fully initialized (e.g., during language server startup). await Helper.RetryAsync(ct => { + // Query whether the command is currently available ErrorHandler.ThrowOnFailure(dispatcher.QueryStatus(ref commandGuid, 1, cmds, IntPtr.Zero)); var status = (OLECMDF)cmds[0].cmdf; @@ -103,6 +108,7 @@ await Helper.RetryAsync(ct => return SpecializedTasks.False; }, TimeSpan.FromMilliseconds(100), cancellationToken); + // Execute the command now that we've confirmed it's ready ErrorHandler.ThrowOnFailure(dispatcher.Exec(commandGuid, commandId, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero)); }