Skip to content

Commit c1e5fcc

Browse files
authored
Resolve ILLink warnings in Microsoft.Extensions.Hosting (#55048)
1 parent f4e88f4 commit c1e5fcc

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

src/libraries/Microsoft.Extensions.Hosting/src/ILLink/ILLink.Suppressions.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/libraries/Microsoft.Extensions.Hosting/src/OptionsBuilderExtensions.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Microsoft.Extensions.DependencyInjection
1010
/// <summary>
1111
/// Extension methods for adding configuration related options services to the DI container via <see cref="OptionsBuilder{TOptions}"/>.
1212
/// </summary>
13+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2091:UnrecognizedReflectionPattern",
14+
Justification = "Workaround for https://github.com/mono/linker/issues/1416. Outer method has been annotated with DynamicallyAccessedMembers.")]
1315
public static class OptionsBuilderExtensions
1416
{
1517
/// <summary>
@@ -28,23 +30,14 @@ public static class OptionsBuilderExtensions
2830

2931
optionsBuilder.Services.AddHostedService<ValidationHostedService>();
3032
optionsBuilder.Services.AddOptions<ValidatorOptions>()
31-
.Configure<IOptionsMonitor<TOptions>>((vo, options) => ValidateOnStartHelper(vo, options, optionsBuilder));
33+
.Configure<IOptionsMonitor<TOptions>>((vo, options) =>
34+
{
35+
// This adds an action that resolves the options value to force evaluation
36+
// We don't care about the result as duplicates are not important
37+
vo.Validators[typeof(TOptions)] = () => options.Get(optionsBuilder.Name);
38+
});
3239

3340
return optionsBuilder;
3441
}
35-
36-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2091:UnrecognizedReflectionPattern",
37-
Justification = "Workaround for https://github.com/mono/linker/issues/1416. Outer method has been annotated with DynamicallyAccessedMembers.")]
38-
private static void ValidateOnStartHelper<TOptions>(ValidatorOptions vo, IOptionsMonitor<TOptions> options, OptionsBuilder<TOptions> optionsBuilder)
39-
where TOptions : class
40-
{
41-
// This adds an action that resolves the options value to force evaluation
42-
// We don't care about the result as duplicates are not important
43-
vo.Validators[typeof(TOptions)] = () => GetOptionsMethod(options, optionsBuilder);
44-
}
45-
46-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2091:UnrecognizedReflectionPattern",
47-
Justification = "Workaround for https://github.com/mono/linker/issues/1416. Outer method has been annotated with DynamicallyAccessedMembers.")]
48-
private static void GetOptionsMethod<TOptions>(IOptionsMonitor<TOptions> options, OptionsBuilder<TOptions> optionsBuilder) where TOptions : class => options.Get(optionsBuilder.Name);
4942
}
5043
}

0 commit comments

Comments
 (0)