diff --git a/src/Adapter/MSTestAdapter.PlatformServices/SourceGeneration/SourceGeneratedReflectionOperations.cs b/src/Adapter/MSTestAdapter.PlatformServices/SourceGeneration/SourceGeneratedReflectionOperations.cs index cf6ed80411..b86bb7516c 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/SourceGeneration/SourceGeneratedReflectionOperations.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/SourceGeneration/SourceGeneratedReflectionOperations.cs @@ -319,17 +319,15 @@ public bool IsAttributeDefined(ICustomAttributeProvider attributePro TAttribute? first = null; foreach (Attribute attr in GetCustomAttributesCached(attributeProvider)) { - if (attr is not TAttribute match) + if (attr is TAttribute match) { - continue; - } + if (first is not null) + { + throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Found multiple attributes of type '{0}' when only one was expected.", typeof(TAttribute))); + } - if (first is not null) - { - throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Found multiple attributes of type '{0}' when only one was expected.", typeof(TAttribute))); + first = match; } - - first = match; } return first; diff --git a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackagedAppTestHostHandle.cs b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackagedAppTestHostHandle.cs index 01debf9433..beedb00ea5 100644 --- a/src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackagedAppTestHostHandle.cs +++ b/src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackagedAppTestHostHandle.cs @@ -56,11 +56,7 @@ public void Dispose() Directory.Delete(_deploymentDirectory, recursive: true); } } - catch (IOException ex) - { - Debug.WriteLine($"Best-effort cleanup of deployment directory '{_deploymentDirectory}' failed: {ex}"); - } - catch (UnauthorizedAccessException ex) + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) { Debug.WriteLine($"Best-effort cleanup of deployment directory '{_deploymentDirectory}' failed: {ex}"); }