diff options
author | James Newton-King <james@newtonking.com> | 2022-04-01 09:15:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 09:15:37 +0300 |
commit | 5955a453d40ed51f0c72aaf187cd317f3dfd67ad (patch) | |
tree | d05df6e08951d82c9366c68d5a2007e4fdecc705 | |
parent | 21905a809ad8d7e6a8e7f2bf603326a09c27d4df (diff) | |
parent | b6630137b2109042dc11ece3164782e451647bff (diff) |
Merge branch 'main' into jamesnk/trim-iis-httpsysjamesnk/trim-iis-httpsys
10 files changed, 36 insertions, 6 deletions
diff --git a/eng/TrimmableProjects.props b/eng/TrimmableProjects.props index 3b1d726fdc..c7c6455cf8 100644 --- a/eng/TrimmableProjects.props +++ b/eng/TrimmableProjects.props @@ -24,6 +24,10 @@ <TrimmableProject Include="Microsoft.AspNetCore.Server.HttpSys" /> <TrimmableProject Include="Microsoft.AspNetCore.Server.IISIntegration" /> <TrimmableProject Include="Microsoft.AspNetCore.Server.IIS" /> + <TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel.Core" /> + <TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel" /> + <TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Quic" /> + <TrimmableProject Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" /> <TrimmableProject Include="Microsoft.AspNetCore.Authorization" /> <TrimmableProject Include="Microsoft.AspNetCore.HttpOverrides" /> <TrimmableProject Include="Microsoft.AspNetCore.Components.Authorization" /> diff --git a/src/Servers/Kestrel/Core/src/Internal/ConfigurationReader.cs b/src/Servers/Kestrel/Core/src/Internal/ConfigurationReader.cs index 7af930b47d..98f20c41ad 100644 --- a/src/Servers/Kestrel/Core/src/Internal/ConfigurationReader.cs +++ b/src/Servers/Kestrel/Core/src/Internal/ConfigurationReader.cs @@ -184,7 +184,17 @@ internal class ConfigurationReader private static SslProtocols? ParseSslProcotols(IConfigurationSection sslProtocols) { - var stringProtocols = sslProtocols.Get<string[]>(); + // Avoid trimming warning from IConfigurationSection.Get<string[]>() + string[]? stringProtocols = null; + var childrenSections = sslProtocols.GetChildren().ToArray(); + if (childrenSections.Length > 0) + { + stringProtocols = new string[childrenSections.Length]; + for (var i = 0; i < childrenSections.Length; i++) + { + stringProtocols[i] = childrenSections[i].Value!; + } + } return stringProtocols?.Aggregate(SslProtocols.None, (acc, current) => { diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs index a27fe898ce..013a8bc98d 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs @@ -1343,12 +1343,19 @@ internal abstract partial class HttpProtocol : IHttpResponseControl const string badRequestEventName = "Microsoft.AspNetCore.Server.Kestrel.BadRequest"; if (ServiceContext.DiagnosticSource?.IsEnabled(badRequestEventName) == true) { - ServiceContext.DiagnosticSource.Write(badRequestEventName, this); + WriteDiagnosticEvent(ServiceContext.DiagnosticSource, badRequestEventName, this); } _keepAlive = false; } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", + Justification = "The values being passed into Write are being consumed by the application already.")] + private static void WriteDiagnosticEvent(DiagnosticSource diagnosticSource, string name, HttpProtocol value) + { + diagnosticSource.Write(name, value); + } + public void ReportApplicationError(Exception? ex) { // ReportApplicationError can be called with a null exception from MessageBody diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelEventSource.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelEventSource.cs index d9392bbc60..d70f295af7 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelEventSource.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelEventSource.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Buffers; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Net.Security; using System.Runtime.CompilerServices; @@ -200,6 +201,7 @@ internal sealed class KestrelEventSource : EventSource [MethodImpl(MethodImplOptions.NoInlining)] [Event(9, Level = EventLevel.Informational)] + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primative values.")] private void TlsHandshakeStop(string connectionId, string sslProtocols, string applicationProtocol, string hostName) { WriteEvent(9, connectionId, sslProtocols, applicationProtocol, hostName); @@ -377,6 +379,7 @@ internal sealed class KestrelEventSource : EventSource [NonEvent] [SkipLocalsInit] + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primative values.")] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3, string? arg4, string? arg5) { const int EventDataCount = 5; diff --git a/src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj b/src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj index 601d134c45..9b1b4a629c 100644 --- a/src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj +++ b/src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj @@ -10,7 +10,7 @@ <IsPackable>false</IsPackable> <DefineConstants>$(DefineConstants);KESTREL</DefineConstants> <NoWarn>$(NoWarn);IDE0060</NoWarn><!-- APIs in HTTP3 are work in progress and produce these warnings frequently--> - <Nullable>enable</Nullable> + <Trimmable>true</Trimmable> </PropertyGroup> <ItemGroup> diff --git a/src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj b/src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj index 106684e5cd..6df959f1cf 100644 --- a/src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj +++ b/src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj @@ -7,7 +7,7 @@ <GenerateDocumentationFile>true</GenerateDocumentationFile> <PackageTags>aspnetcore;kestrel</PackageTags> <IsPackable>false</IsPackable> - <Nullable>enable</Nullable> + <Trimmable>true</Trimmable> </PropertyGroup> <ItemGroup> diff --git a/src/Servers/Kestrel/Transport.Quic/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj b/src/Servers/Kestrel/Transport.Quic/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj index fef4201f8a..3018f75961 100644 --- a/src/Servers/Kestrel/Transport.Quic/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj +++ b/src/Servers/Kestrel/Transport.Quic/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj @@ -10,7 +10,7 @@ <NoWarn>CA1416;CS0436;$(NoWarn)</NoWarn><!-- Conflicts between internal and public Quic APIs; Platform support warnings. --> <NoWarn>$(NoWarn);IDE0060</NoWarn> <!-- This project is work in progress and has incomplete APIs --> <IsPackable>false</IsPackable> - <Nullable>enable</Nullable> + <Trimmable>true</Trimmable> </PropertyGroup> <ItemGroup> diff --git a/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj b/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj index e124cd336b..f749580ec2 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj +++ b/src/Servers/Kestrel/Transport.Sockets/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj @@ -8,7 +8,7 @@ <PackageTags>aspnetcore;kestrel</PackageTags> <AllowUnsafeBlocks>true</AllowUnsafeBlocks> <IsPackable>false</IsPackable> - <Nullable>enable</Nullable> + <Trimmable>true</Trimmable> </PropertyGroup> <ItemGroup> diff --git a/src/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index 0333fdc3e2..9f7baf1de2 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.IO; using System.Linq; @@ -786,6 +787,7 @@ internal abstract class CertificateManager public class CertificateManagerEventSource : EventSource { [Event(1, Level = EventLevel.Verbose, Message = "Listing certificates from {0}\\{1}")] + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primative values.")] public void ListCertificatesStart(StoreLocation location, StoreName storeName) => WriteEvent(1, location, storeName); [Event(2, Level = EventLevel.Verbose, Message = "Found certificates: {0}")] @@ -831,6 +833,7 @@ internal abstract class CertificateManager public void CreateDevelopmentCertificateError(string e) => WriteEvent(19, e); [Event(20, Level = EventLevel.Verbose, Message = "Saving certificate '{0}' to store {2}\\{1}.")] + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primative values.")] public void SaveCertificateInStoreStart(string certificate, StoreName name, StoreLocation location) => WriteEvent(20, certificate, name, location); [Event(21, Level = EventLevel.Verbose, Message = "Finished saving certificate to the store.")] diff --git a/src/Shared/runtime/NetEventSource.Common.cs b/src/Shared/runtime/NetEventSource.Common.cs index 8a9440006f..ff93dca9c5 100644 --- a/src/Shared/runtime/NetEventSource.Common.cs +++ b/src/Shared/runtime/NetEventSource.Common.cs @@ -10,6 +10,7 @@ #nullable enable using System.Collections; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; using System.Globalization; using System.Runtime.CompilerServices; @@ -440,6 +441,7 @@ namespace System.Net #region Custom WriteEvent overloads [NonEvent] + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primative values.")] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3, string? arg4) { if (IsEnabled()) @@ -484,6 +486,7 @@ namespace System.Net } [NonEvent] + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primative values.")] private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, byte[]? arg3) { if (IsEnabled()) |