From 4e80e7611f27a758b70b7356759c65bd57eb2b11 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Tue, 31 Jan 2023 06:13:55 +0100 Subject: [PATCH] Adding missing guard for telemetry optout to avoid NRE when importing modules (#18949) --- src/System.Management.Automation/utils/Telemetry.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/System.Management.Automation/utils/Telemetry.cs b/src/System.Management.Automation/utils/Telemetry.cs index 3d9f3c9e1f..6ae1a93d6d 100644 --- a/src/System.Management.Automation/utils/Telemetry.cs +++ b/src/System.Management.Automation/utils/Telemetry.cs @@ -661,6 +661,11 @@ namespace Microsoft.PowerShell.Telemetry /// The module version to report. The default value is the anonymous version '0.0.0.0'. internal static void SendModuleTelemetryMetric(TelemetryType telemetryType, string moduleName, string moduleVersion = AnonymousVersion) { + if (!CanSendTelemetry) + { + return; + } + try { string allowedModuleName = GetModuleName(moduleName);