diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.cs index 89716bf326..ba1ecc6d21 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/DataReader.cs @@ -55,10 +55,10 @@ bool IDataReader.GetThreadContext(uint threadId, uint contextFlags, Span c try { byte[] registerContext = ThreadService.GetThreadFromId(threadId).GetThreadContext(); - context = new Span(registerContext); + registerContext.AsSpan().Slice(0, context.Length).CopyTo(context); return true; } - catch (DiagnosticsException ex) + catch (Exception ex) when (ex is DiagnosticsException or ArgumentException) { Trace.TraceError($"GetThreadContext: {threadId} exception {ex.Message}"); }