diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicConnection.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicConnection.cs index ef881266891de7..6fb65889585133 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicConnection.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicConnection.cs @@ -712,10 +712,14 @@ private void Dispose(bool disposing) if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(_state, $"{TraceId()} Stream disposing {disposing}"); // If we haven't already shutdown gracefully (via a successful CloseAsync call), then force an abortive shutdown. - MsQuicApi.Api.ConnectionShutdownDelegate( - _state.Handle, - QUIC_CONNECTION_SHUTDOWN_FLAGS.SILENT, - 0); + if (_state.Handle != null) + { + // Handle can be null if outbound constructor failed and we are called from finalizer. + MsQuicApi.Api.ConnectionShutdownDelegate( + _state.Handle, + QUIC_CONNECTION_SHUTDOWN_FLAGS.SILENT, + 0); + } bool releaseHandles = false; lock (_state)