diff --git a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs index 2cbb76e5b1..2f44503c0e 100644 --- a/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs +++ b/src/Kestrel.Core/Adapter/Internal/AdaptedPipeline.cs @@ -76,9 +76,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { #if NETCOREAPP2_1 await stream.WriteAsync(buffer.First); -#else +#elif NETSTANDARD2_0 var array = buffer.First.GetArray(); await stream.WriteAsync(array.Array, array.Offset, array.Count); +#else +#error TFMs need to be updated #endif } else @@ -87,9 +89,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { #if NETCOREAPP2_1 await stream.WriteAsync(memory); -#else +#elif NETSTANDARD2_0 var array = memory.GetArray(); await stream.WriteAsync(array.Array, array.Offset, array.Count); +#else +#error TFMs need to be updated #endif } } @@ -129,9 +133,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal var outputBuffer = Input.Writer.GetMemory(MinAllocBufferSize); #if NETCOREAPP2_1 var bytesRead = await stream.ReadAsync(outputBuffer); -#else +#elif NETSTANDARD2_0 var array = outputBuffer.GetArray(); var bytesRead = await stream.ReadAsync(array.Array, array.Offset, array.Count); +#else +#error TFMs need to be updated #endif Input.Writer.Advance(bytesRead); diff --git a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs index f9225b6f48..e591d4acf4 100644 --- a/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/LoggingStream.cs @@ -90,6 +90,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal Log("Read", destination.Slice(0, read)); return read; } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public async override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -106,6 +109,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal Log("ReadAsync", destination.Span.Slice(0, read)); return read; } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public override long Seek(long offset, SeekOrigin origin) @@ -130,6 +136,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal Log("Write", source); _inner.Write(source); } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -144,6 +153,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal Log("WriteAsync", source.Span); return _inner.WriteAsync(source, cancellationToken); } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif private void Log(string method, ReadOnlySpan buffer) diff --git a/src/Kestrel.Core/Adapter/Internal/RawStream.cs b/src/Kestrel.Core/Adapter/Internal/RawStream.cs index 7be7d276f8..4f35b95ebe 100644 --- a/src/Kestrel.Core/Adapter/Internal/RawStream.cs +++ b/src/Kestrel.Core/Adapter/Internal/RawStream.cs @@ -74,6 +74,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal { return ReadAsyncInternal(destination); } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public override void Write(byte[] buffer, int offset, int count) @@ -97,6 +100,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal _output.Write(source.Span); await _output.FlushAsync(cancellationToken); } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public override void Flush() diff --git a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs index 51b7e7b6cd..ff9c9a9d47 100644 --- a/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpRequestStream.cs @@ -117,6 +117,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return ReadAsyncInternal(destination, cancellationToken); } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif private async ValueTask ReadAsyncInternal(Memory buffer, CancellationToken cancellationToken) diff --git a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs index aefbe6fb19..0831c74fbf 100644 --- a/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpResponseStream.cs @@ -118,6 +118,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http return new ValueTask(_httpResponseControl.WriteAsync(source, cancellationToken)); } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public void StartAcceptingWrites() diff --git a/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs b/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs index d6fedc0518..0b89d00ed1 100644 --- a/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs +++ b/src/Kestrel.Core/Internal/Http/HttpUpgradeStream.cs @@ -150,6 +150,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return _requestStream.ReadAsync(destination, cancellationToken); } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) @@ -167,6 +170,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { return _responseStream.WriteAsync(source, cancellationToken); } +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public override long Seek(long offset, SeekOrigin origin) diff --git a/src/Kestrel.Core/Internal/Http/MessageBody.cs b/src/Kestrel.Core/Internal/Http/MessageBody.cs index d96aa99d47..339c9d182a 100644 --- a/src/Kestrel.Core/Internal/Http/MessageBody.cs +++ b/src/Kestrel.Core/Internal/Http/MessageBody.cs @@ -90,9 +90,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http // - We change the Kestrel Memory Pool to not use pinned arrays but instead use native memory #if NETCOREAPP2_1 await destination.WriteAsync(memory); -#else +#elif NETSTANDARD2_0 var array = memory.GetArray(); await destination.WriteAsync(array.Array, array.Offset, array.Count, cancellationToken); +#else +#error TFMs need to be updated #endif } } diff --git a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index 95ee435b43..4058635e68 100644 --- a/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal } await sslStream.AuthenticateAsServerAsync(sslOptions, CancellationToken.None); -#else +#elif NETSTANDARD2_0 // No ALPN support var serverCert = _serverCertificate; if (_serverCertificateSelector != null) { @@ -179,6 +179,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal } await sslStream.AuthenticateAsServerAsync(serverCert, certificateRequired, _options.SslProtocols, _options.CheckCertificateRevocation); +#else +#error TFMs need to be updated #endif } catch (OperationCanceledException) @@ -201,6 +203,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal #if NETCOREAPP2_1 feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.Protocol; context.Features.Set(feature); +#elif NETSTANDARD2_0 // No ALPN support +#else +#error TFMs need to be updated #endif feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate); diff --git a/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs b/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs index 9485392825..0be1c97d7e 100644 --- a/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs +++ b/src/Kestrel.Core/Internal/Infrastructure/WrappingStream.cs @@ -71,6 +71,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure #if NETCOREAPP2_1 public override ValueTask ReadAsync(Memory destination, CancellationToken cancellationToken = default) => _inner.ReadAsync(destination, cancellationToken); +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public override int ReadByte() @@ -91,6 +94,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure #if NETCOREAPP2_1 public override ValueTask WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) => _inner.WriteAsync(source, cancellationToken); +#elif NETSTANDARD2_0 +#else +#error TFMs need to be updated #endif public override void WriteByte(byte value) diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs index 2116c03cd5..223d5e9b70 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketReceiver.cs @@ -25,10 +25,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal { #if NETCOREAPP2_1 _eventArgs.SetBuffer(buffer); -#else +#elif NETSTANDARD2_0 var segment = buffer.GetArray(); _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); +#else +#error TFMs need to be updated #endif if (!_socket.ReceiveAsync(_eventArgs)) { diff --git a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs index 26e22b664d..0684560d87 100644 --- a/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs +++ b/src/Kestrel.Transport.Sockets/Internal/SocketSender.cs @@ -36,8 +36,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal #if NETCOREAPP2_1 if (!_eventArgs.MemoryBuffer.Equals(Memory.Empty)) -#else +#elif NETSTANDARD2_0 if (_eventArgs.Buffer != null) +#else +#error TFMs need to be updated #endif { _eventArgs.SetBuffer(null, 0, 0); @@ -63,10 +65,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal #if NETCOREAPP2_1 _eventArgs.SetBuffer(MemoryMarshal.AsMemory(memory)); -#else +#elif NETSTANDARD2_0 var segment = memory.GetArray(); _eventArgs.SetBuffer(segment.Array, segment.Offset, segment.Count); +#else +#error TFMs need to be updated #endif if (!_socket.SendAsync(_eventArgs)) { diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index 6f7b55a3a2..7798820b10 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -154,8 +154,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.NotNull(connection.Features.Get()); #if NETCOREAPP2_2 Assert.Equal("localhost", name); -#else +#elif NET461 Assert.Null(name); +#else +#error TFMs need to be updated #endif selectorCalled++; return _x509Certificate2; @@ -194,8 +196,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.NotNull(connection.Features.Get()); #if NETCOREAPP2_2 Assert.Equal("localhost", name); -#else +#elif NET461 Assert.Null(name); +#else +#error TFMs need to be updated #endif selectorCalled++; if (selectorCalled == 1) @@ -282,8 +286,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests Assert.NotNull(connection.Features.Get()); #if NETCOREAPP2_2 Assert.Equal("localhost", name); -#else +#elif NET461 Assert.Null(name); +#else +#error TFMs need to be updated #endif selectorCalled++; return _x509Certificate2; diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index cfad5c7e7c..351a2c9e93 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.Testing _innerStream.Close(); } -#if NETCOREAPP2_1 +#if NETCOREAPP2_2 public override int Read(Span buffer) { return _innerStream.Read(buffer); @@ -165,7 +165,10 @@ namespace Microsoft.AspNetCore.Testing { _innerStream.CopyTo(destination, bufferSize); } -#endif +#elif NET461 +#else +#error TFMs need to be updated +#endif } } } diff --git a/test/shared/TestApplicationErrorLogger.cs b/test/shared/TestApplicationErrorLogger.cs index 2f05ec174c..bff77f8efa 100644 --- a/test/shared/TestApplicationErrorLogger.cs +++ b/test/shared/TestApplicationErrorLogger.cs @@ -45,9 +45,8 @@ namespace Microsoft.AspNetCore.Testing public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { var exceptionIsIgnored = IgnoredExceptions.Contains(exception?.GetType()); -#if true + if (logLevel == LogLevel.Critical && ThrowOnCriticalErrors && !exceptionIsIgnored) -#endif { var log = $"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception}";