Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address remaining trim warnings #4962

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
<!-- This is false for local development, but set to true in the CI system -->
<TreatWarningsAsErrors Condition=" '$(TreatWarningsAsErrors)' == '' ">false</TreatWarningsAsErrors>

<!-- See https://github.com/dotnet/extensions/issues/4395 -->
<NoWarn>$(NoWarn);TBD</NoWarn>
Comment on lines -19 to -20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


<!-- TODO: to be re-enabled and all warnings fixed (https://github.com/dotnet/extensions/issues/4002) -->
<NoWarn>$(NoWarn);IL2026;IL2087;IL2067;CA1825</NoWarn>

<!-- Prevent analyzer crashes from stopping things -->
<NoWarn>$(NoWarn);AD0001</NoWarn>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

<PropertyGroup>
<TargetFrameworks>$(NetCoreTargetFrameworks)</TargetFrameworks>
<!-- blocked by https://github.com/dotnet/runtime/issues/94547 -->
<IsAotCompatible>false</IsAotCompatible>
<UseLoggingGenerator>true</UseLoggingGenerator>
<UseMetricsGenerator>true</UseMetricsGenerator>
<InjectExperimentalAttributeOnLegacy>true</InjectExperimentalAttributeOnLegacy>
<InjectGetOrAddOnLegacy>true</InjectGetOrAddOnLegacy>

<!-- using the ConfigurationBinder source generator is blocked by https://github.com/dotnet/runtime/issues/94547 -->
<IsAotCompatible>false</IsAotCompatible>
<NoWarn>$(NoWarn);IL2026</NoWarn>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Compliance.Classification;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -24,14 +25,14 @@ public interface IRedactionBuilder
/// <param name="classifications">The data classifications for which the redactor type should be used.</param>
/// <returns>The value of this instance.</returns>
/// <exception cref="ArgumentNullException"><paramref name="classifications" /> is <see langword="null" />.</exception>
IRedactionBuilder SetRedactor<T>(params DataClassificationSet[] classifications)
IRedactionBuilder SetRedactor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(params DataClassificationSet[] classifications)
where T : Redactor;

/// <summary>
/// Sets the redactor to use when processing classified data for which no specific redactor has been registered.
/// </summary>
/// <typeparam name="T">Redactor type.</typeparam>
/// <returns>The value of this instance.</returns>
IRedactionBuilder SetFallbackRedactor<T>()
IRedactionBuilder SetFallbackRedactor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>()
where T : Redactor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class HmacRedactorOptions
#if NET8_0_OR_GREATER
[System.ComponentModel.DataAnnotations.Base64String]
#endif
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "Validating the Length attribute on a string does not require reflection, it is handled intrinsically.")]
[Microsoft.Shared.Data.Validation.Length(44)]
public string Key { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Compliance.Classification;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand Down Expand Up @@ -29,7 +30,7 @@ public RedactionBuilder(IServiceCollection services)
Services.TryAddEnumerable(ServiceDescriptor.Singleton<Redactor>(NullRedactor.Instance));
}

public IRedactionBuilder SetRedactor<T>(params DataClassificationSet[] classifications)
public IRedactionBuilder SetRedactor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(params DataClassificationSet[] classifications)
where T : Redactor
{
_ = Throw.IfNull(classifications);
Expand All @@ -44,7 +45,7 @@ public IRedactionBuilder SetRedactor<T>(params DataClassificationSet[] classific
return this;
}

public IRedactionBuilder SetFallbackRedactor<T>()
public IRedactionBuilder SetFallbackRedactor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>()
where T : Redactor
{
Services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(Redactor), typeof(T)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static IServiceCollection AddActivatedKeyedSingleton<TService>(
/// <returns>The value of <paramref name="services" />.</returns>
public static IServiceCollection AddActivatedKeyedSingleton(
this IServiceCollection services,
Type serviceType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type serviceType,
object? serviceKey)
{
_ = Throw.IfNull(services);
Expand Down Expand Up @@ -224,7 +224,7 @@ public static IServiceCollection AddActivatedKeyedSingleton(
this IServiceCollection services,
Type serviceType,
object? serviceKey,
Type implementationType)
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType)
{
_ = Throw.IfNull(services);
_ = Throw.IfNull(serviceType);
Expand All @@ -243,7 +243,7 @@ public static IServiceCollection AddActivatedKeyedSingleton(
/// <param name="serviceKey">An object used to uniquely identify the specific service.</param>
public static void TryAddActivatedKeyedSingleton(
this IServiceCollection services,
Type serviceType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type serviceType,
object? serviceKey)
{
_ = Throw.IfNull(services);
Expand All @@ -263,7 +263,7 @@ public static void TryAddActivatedKeyedSingleton(
this IServiceCollection services,
Type serviceType,
object? serviceKey,
Type implementationType)
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType)
{
_ = Throw.IfNull(services);
_ = Throw.IfNull(serviceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ public static IServiceCollection AddActivatedSingleton<TService>(this IServiceCo
/// <param name="services">The service collection to add the service to.</param>
/// <param name="serviceType">The type of the service to register and the implementation to use.</param>
/// <returns>The value of <paramref name="services" />.</returns>
public static IServiceCollection AddActivatedSingleton(this IServiceCollection services, Type serviceType)
public static IServiceCollection AddActivatedSingleton(
this IServiceCollection services,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type serviceType)
{
_ = Throw.IfNull(services);
_ = Throw.IfNull(serviceType);
Expand All @@ -183,7 +185,10 @@ public static IServiceCollection AddActivatedSingleton(this IServiceCollection s
/// <param name="serviceType">The type of the service to register.</param>
/// <param name="implementationFactory">The factory that creates the service.</param>
/// <returns>The value of <paramref name="services" />.</returns>
public static IServiceCollection AddActivatedSingleton(this IServiceCollection services, Type serviceType, Func<IServiceProvider, object> implementationFactory)
public static IServiceCollection AddActivatedSingleton(
this IServiceCollection services,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type serviceType,
Func<IServiceProvider, object> implementationFactory)
{
_ = Throw.IfNull(services);
_ = Throw.IfNull(serviceType);
Expand All @@ -201,7 +206,10 @@ public static IServiceCollection AddActivatedSingleton(this IServiceCollection s
/// <param name="serviceType">The type of the service to register.</param>
/// <param name="implementationType">The implementation type of the service.</param>
/// <returns>The value of <paramref name="services" />.</returns>
public static IServiceCollection AddActivatedSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
public static IServiceCollection AddActivatedSingleton(
this IServiceCollection services,
Type serviceType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType)
{
_ = Throw.IfNull(services);
_ = Throw.IfNull(serviceType);
Expand All @@ -217,7 +225,9 @@ public static IServiceCollection AddActivatedSingleton(this IServiceCollection s
/// </summary>
/// <param name="services">The service collection to add the service to.</param>
/// <param name="serviceType">The type of the service to register.</param>
public static void TryAddActivatedSingleton(this IServiceCollection services, Type serviceType)
public static void TryAddActivatedSingleton(
this IServiceCollection services,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type serviceType)
{
_ = Throw.IfNull(services);
_ = Throw.IfNull(serviceType);
Expand All @@ -231,7 +241,10 @@ public static void TryAddActivatedSingleton(this IServiceCollection services, Ty
/// <param name="services">The service collection to add the service to.</param>
/// <param name="serviceType">The type of the service to register.</param>
/// <param name="implementationType">The implementation type of the service.</param>
public static void TryAddActivatedSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
public static void TryAddActivatedSingleton(
this IServiceCollection services,
Type serviceType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type implementationType)
{
_ = Throw.IfNull(services);
_ = Throw.IfNull(serviceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand Down Expand Up @@ -118,8 +119,8 @@ public static IStandardHedgingHandlerBuilder AddStandardHedgingHandler(this IHtt
var routingOptions = context.GetOptions<RequestRoutingOptions>(routingBuilder.Name);

_ = builder
.AddStrategy(_ => new RoutingResilienceStrategy(routingOptions.RoutingStrategyProvider), new EmptyResilienceStrategyOptions())
.AddStrategy(_ => new RequestMessageSnapshotStrategy(), new EmptyResilienceStrategyOptions())
.AddStrategy(_ => new RoutingResilienceStrategy(routingOptions.RoutingStrategyProvider))
.AddStrategy(_ => new RequestMessageSnapshotStrategy())
.AddTimeout(options.TotalRequestTimeout)
.AddHedging(options.Hedging);
});
Expand All @@ -142,6 +143,11 @@ public static IStandardHedgingHandlerBuilder AddStandardHedgingHandler(this IHtt
return new StandardHedgingHandlerBuilder(builder.Name, builder.Services, routingBuilder);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "The EmptyResilienceStrategyOptions doesn't have any properties to validate.")]
private static ResiliencePipelineBuilder<HttpResponseMessage> AddStrategy(this ResiliencePipelineBuilder<HttpResponseMessage> builder, Func<StrategyBuilderContext, ResilienceStrategy> factory) =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martintmk - do you think Polly could expose this API instead? That way callers wouldn't have to define an empty ResilienceStrategyOptions class and suppress the warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could. Could you create an issue in Polly repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builder.AddStrategy(factory, new EmptyResilienceStrategyOptions());

private sealed record StandardHedgingHandlerBuilder(
string Name,
IServiceCollection Services,
Expand Down