diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs index 81f9f69503..cc4c18c914 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; @@ -387,7 +388,7 @@ private void CleanupPlugins() /// The friendly Name. /// The data collector Uri. /// - protected virtual bool TryGetUriFromFriendlyName(string? friendlyName, out string? dataCollectorUri) + protected virtual bool TryGetUriFromFriendlyName(string? friendlyName, [NotNullWhen(true)] out string? dataCollectorUri) { TPDebug.Assert(_dataCollectorExtensionManager is not null, "_dataCollectorExtensionManager is null"); foreach (var extension in _dataCollectorExtensionManager.TestExtensions) diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs index 1038fca464..519ee34410 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs @@ -96,14 +96,13 @@ public string GetMonoPath() return monoPath; } - private bool TryGetExecutablePath(string executableBaseName, out string executablePath) + private bool TryGetExecutablePath(string executableBaseName, [NotNullWhen(true)] out string? executablePath) { if (_environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows)) { executableBaseName += ".exe"; } - executablePath = string.Empty; var pathString = Environment.GetEnvironmentVariable("PATH")!; foreach (string path in pathString.Split(Path.PathSeparator)) { @@ -115,6 +114,7 @@ private bool TryGetExecutablePath(string executableBaseName, out string executab } } + executablePath = null; return false; } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs index 4a926b137c..947c1bad04 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/TestLoggerManager.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Reflection; @@ -387,7 +388,7 @@ internal bool InitializeLoggerByUri(Uri uri, Dictionary? parame /// The friendly Name. /// The logger Uri. /// - internal bool TryGetUriFromFriendlyName(string? friendlyName, out Uri? loggerUri) + internal bool TryGetUriFromFriendlyName(string? friendlyName, [NotNullWhen(true)] out Uri? loggerUri) { var extensionManager = TestLoggerExtensionManager; foreach (var extension in extensionManager.TestExtensions)