Skip to content

Commit 26b04c7

Browse files
committed
CancellationHelper: Improved compatibility with .NET Standard 2.0
1 parent 23e74bf commit 26b04c7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

StandardSocketsHttpHandler/Net/Http/SocketsHttpHandler/CancellationHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ internal static bool ShouldWrapInOperationCanceledException(Exception exception,
2525
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that triggered the cancellation.</param>
2626
/// <returns>The cancellation exception.</returns>
2727
internal static Exception CreateOperationCanceledException(Exception innerException, CancellationToken cancellationToken) =>
28+
#if NETSTANDARD20
29+
new TaskCanceledException(s_cancellationMessage, innerException); // TCE for compatibility with other handlers that use TaskCompletionSource.TrySetCanceled()
30+
#else
2831
new TaskCanceledException(s_cancellationMessage, innerException, cancellationToken); // TCE for compatibility with other handlers that use TaskCompletionSource.TrySetCanceled()
32+
#endif
2933

3034
/// <summary>Throws a cancellation exception.</summary>
3135
/// <param name="innerException">The inner exception to wrap. May be null.</param>

0 commit comments

Comments
 (0)