From 0d6cf6682cd37349c8e18d8bbf671757f8a4c3ac Mon Sep 17 00:00:00 2001 From: Joe Schmitt Date: Mon, 1 Jul 2024 13:15:04 -0700 Subject: [PATCH] Nullability fixes --- .../Controllers/DiagController.cs | 4 +--- .../Controllers/MetricsController.cs | 4 +--- .../TaskCompletionSourceExtensions.cs | 6 ++---- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs index 60bea0b1635..f4097f4509e 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs @@ -35,9 +35,7 @@ public partial class DiagController : DiagnosticsControllerBase { private const TraceProfile DefaultTraceProfiles = TraceProfile.Cpu | TraceProfile.Http | TraceProfile.Metrics | TraceProfile.GcCollect; -#nullable disable private readonly IOptions _diagnosticPortOptions; -#nullable restore private readonly IOptions _callStacksOptions; private readonly IOptions _parameterCapturingOptions; private readonly IOptionsMonitor _counterOptions; @@ -54,7 +52,7 @@ public partial class DiagController : DiagnosticsControllerBase public DiagController(IServiceProvider serviceProvider, ILogger logger) : base(serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), logger) { - _diagnosticPortOptions = serviceProvider.GetService>(); + _diagnosticPortOptions = serviceProvider.GetRequiredService>(); _callStacksOptions = serviceProvider.GetRequiredService>(); _parameterCapturingOptions = serviceProvider.GetRequiredService>(); _counterOptions = serviceProvider.GetRequiredService>(); diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/MetricsController.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/MetricsController.cs index e4f8538b921..1b14cb49b6c 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/MetricsController.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/MetricsController.cs @@ -21,9 +21,7 @@ public class MetricsController : ControllerBase private const string ArtifactType_Metrics = "metrics"; private readonly ILogger _logger; -#nullable disable private readonly MetricsStoreService _metricsStore; -#nullable restore private readonly MetricsOptions _metricsOptions; public MetricsController(ILogger logger, @@ -31,7 +29,7 @@ public MetricsController(ILogger logger, IOptions metricsOptions) { _logger = logger; - _metricsStore = serviceProvider.GetService(); + _metricsStore = serviceProvider.GetRequiredService(); _metricsOptions = metricsOptions.Value; } diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/TaskCompletionSourceExtensions.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/TaskCompletionSourceExtensions.cs index 321789485ef..f92df62209b 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/TaskCompletionSourceExtensions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/TaskCompletionSourceExtensions.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#nullable disable - using System.Threading; using System.Threading.Tasks; @@ -22,7 +20,7 @@ internal static class TaskCompletionSourceExtensions /// public static async Task WithCancellation(this TaskCompletionSource source, CancellationToken token) { - using (token.Register(source => ((TaskCompletionSource)source).TrySetCanceled(token), source)) + using (token.Register(() => source.TrySetCanceled(token))) { return await source.Task.ConfigureAwait(false); } @@ -30,7 +28,7 @@ public static async Task WithCancellation(this TaskCompletionSource sou public static async Task WithCancellation(this TaskCompletionSource source, CancellationToken token) { - using (token.Register(source => ((TaskCompletionSource)source).TrySetCanceled(token), source)) + using (token.Register(() => source.TrySetCanceled(token))) { await source.Task.ConfigureAwait(false); }