Skip to content

Commit aa218be

Browse files
Copilotstephentoub
andauthored
Address code review: fix null-safety on AggregateException.InnerException
Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/dfc5fff0-2e51-4b55-a663-e9cd3477cad4 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent d3f9b54 commit aa218be

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/ModelContextProtocol.Core/McpSessionHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,9 @@ ex is OperationCanceledException &&
328328
// If the transport's channel was completed with a TransportClosedException,
329329
// propagate it so callers can access the structured completion details.
330330
Exception pendingException =
331-
_transport.MessageReader.Completion is { IsCompleted: true, IsFaulted: true } completion
332-
? completion.Exception!.InnerException!
331+
_transport.MessageReader.Completion is { IsCompleted: true, IsFaulted: true } completion &&
332+
completion.Exception?.InnerException is { } innerException
333+
? innerException
333334
: new IOException("The server shut down unexpectedly.");
334335
foreach (var entry in _pendingRequests)
335336
{

0 commit comments

Comments
 (0)