diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index b34437b7238ccd..1cdeb0dfe222cc 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -1546,27 +1546,40 @@ async Task GetLoadedFiles(SessionId sessionId, ExecutionContext contex protected async Task RuntimeReady(SessionId sessionId, CancellationToken token) { - ExecutionContext context = GetContext(sessionId); - if (Interlocked.CompareExchange(ref context.ready, new TaskCompletionSource(), null) != null) - return await context.ready.Task; - var res = await context.SdbAgent.SendDebuggerAgentCommand(CmdEventRequest.ClearAllBreakpoints, null, token, false); - if (res.HasError) //it's not a wasm page then the command returns an error - return null; + try + { + ExecutionContext context = GetContext(sessionId); + if (Interlocked.CompareExchange(ref context.ready, new TaskCompletionSource(), null) != null) + return await context.ready.Task; + await context.SdbAgent.SendDebuggerAgentCommand(CmdEventRequest.ClearAllBreakpoints, null, token); - if (context.PauseOnExceptions != PauseOnExceptionsKind.None && context.PauseOnExceptions != PauseOnExceptionsKind.Unset) - await context.SdbAgent.EnableExceptions(context.PauseOnExceptions, token); + if (context.PauseOnExceptions != PauseOnExceptionsKind.None && context.PauseOnExceptions != PauseOnExceptionsKind.Unset) + await context.SdbAgent.EnableExceptions(context.PauseOnExceptions, token); - await context.SdbAgent.SetProtocolVersion(token); - await context.SdbAgent.EnableReceiveRequests(EventKind.UserBreak, token); - await context.SdbAgent.EnableReceiveRequests(EventKind.EnC, token); - await context.SdbAgent.EnableReceiveRequests(EventKind.MethodUpdate, token); + await context.SdbAgent.SetProtocolVersion(token); + await context.SdbAgent.EnableReceiveRequests(EventKind.UserBreak, token); + await context.SdbAgent.EnableReceiveRequests(EventKind.EnC, token); + await context.SdbAgent.EnableReceiveRequests(EventKind.MethodUpdate, token); - DebugStore store = await LoadStore(sessionId, true, token); - context.ready.SetResult(store); - await SendEvent(sessionId, "Mono.runtimeReady", new JObject(), token); - await SendMonoCommand(sessionId, MonoCommands.SetDebuggerAttached(RuntimeId), token); - context.SdbAgent.ResetStore(store); - return store; + DebugStore store = await LoadStore(sessionId, true, token); + context.ready.SetResult(store); + await SendEvent(sessionId, "Mono.runtimeReady", new JObject(), token); + await SendMonoCommand(sessionId, MonoCommands.SetDebuggerAttached(RuntimeId), token); + context.SdbAgent.ResetStore(store); + return store; + } + catch (DebuggerAgentException e) + { + //it's not a wasm page then the command throws an error + if (!e.Message.Contains("getDotnetRuntime is not defined")) + logger.LogDebug($"Unexpected error on RuntimeReady {e}"); + return null; + } + catch (Exception e) + { + logger.LogDebug($"Unexpected error on RuntimeReady {e}"); + return null; + } } private static IEnumerable> GetBPReqLocations(DebugStore store, BreakpointRequest req, bool ifNoneFoundThenFindNext = false)