diff --git a/eng/packaging.targets b/eng/packaging.targets
index 3c14f61ae32b6..72401ef6da063 100644
--- a/eng/packaging.targets
+++ b/eng/packaging.targets
@@ -44,9 +44,9 @@
$(MajorVersion).$(MinorVersion).$(ServicingVersion)
<_IsWindowsDesktopApp Condition="$(WindowsDesktopCoreAppLibrary.Contains('$(AssemblyName);'))">true
<_IsAspNetCoreApp Condition="$(AspNetCoreAppLibrary.Contains('$(AssemblyName);'))">true
- <_AssemblyInTargetingPack Condition="'$(IsNETCoreAppSrc)' == 'true' or '$(_IsAspNetCoreApp)' == 'true' or '$(_IsWindowsDesktopApp)' == 'true'">true
+ <_AssemblyInTargetingPack Condition="('$(IsNETCoreAppSrc)' == 'true' or '$(_IsAspNetCoreApp)' == 'true' or '$(_IsWindowsDesktopApp)' == 'true') and '$(TargetFrameworkIdentifier)' != '.NETFramework'">true
- $(MajorVersion).$(MinorVersion).0.$(ServicingVersion)
+ $(MajorVersion).$(MinorVersion).0.$(ServicingVersion)
diff --git a/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj b/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj
index 34f79827374ac..a58b8c1af08d0 100644
--- a/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj
+++ b/src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj
@@ -9,6 +9,8 @@ Commonly Used Types:
System.IO.Pipelines.Pipe
System.IO.Pipelines.PipeWriter
System.IO.Pipelines.PipeReader
+ true
+ 1
{
cancellationToken.ThrowIfCancellationRequested();
- _awaitableState |= AwaitableState.Running;
-
// Don't register if already completed, we would immediately unregistered in ObserveCancellation
if (cancellationToken.CanBeCanceled && !IsCompleted)
{
+#if DEBUG
+ var previousAwaitableState = _awaitableState;
+#endif
+
+ _cancellationTokenRegistration = cancellationToken.UnsafeRegister(callback, state);
+
+ // If we get back the default CancellationTokenRegistration then it means the
+ // callback synchronously and we can throw inline. This is safe because we haven't changed
+ // the state of the awaitable as yet.
+ if (_cancellationTokenRegistration == default(CancellationTokenRegistration))
+ {
+#if DEBUG
+ Debug.Assert(previousAwaitableState == _awaitableState, "The awaitable state changed!");
+#endif
+
+ cancellationToken.ThrowIfCancellationRequested();
+ }
+
#if (NETSTANDARD2_0 || NETFRAMEWORK)
_cancellationToken = cancellationToken;
#endif
- _cancellationTokenRegistration = cancellationToken.UnsafeRegister(callback, state);
}
+
+ _awaitableState |= AwaitableState.Running;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]