From 7448ae67648d0b38eae1935621d5815860842ce7 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Thu, 30 Dec 2021 13:45:07 +1000 Subject: [PATCH 1/5] CA2208 Instantiate argument exceptions correctly --- eng/CodeAnalysis.ruleset | 2 +- src/Build.OM.UnitTests/TransientIO.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset index 2078c42fe6c..88f13bb1a08 100644 --- a/eng/CodeAnalysis.ruleset +++ b/eng/CodeAnalysis.ruleset @@ -126,7 +126,7 @@ - + diff --git a/src/Build.OM.UnitTests/TransientIO.cs b/src/Build.OM.UnitTests/TransientIO.cs index a4baa8399ca..eb0c7fb970d 100644 --- a/src/Build.OM.UnitTests/TransientIO.cs +++ b/src/Build.OM.UnitTests/TransientIO.cs @@ -77,7 +77,7 @@ public string GetAbsolutePath(string relative) var absolute = Path.GetFullPath(Path.IsPathRooted(relative) ? relative : Path.Combine(tempRoot, relative)); if (!IsControled(absolute)) { - throw new ArgumentException(nameof(relative)); + throw new ArgumentException(null, nameof(relative)); } return absolute; From 571f4b708ce6567121116797718c5ffbce69dc06 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Tue, 4 Jan 2022 06:48:22 +1000 Subject: [PATCH 2/5] Add error message --- src/Build.OM.UnitTests/TransientIO.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build.OM.UnitTests/TransientIO.cs b/src/Build.OM.UnitTests/TransientIO.cs index eb0c7fb970d..08f75d4190f 100644 --- a/src/Build.OM.UnitTests/TransientIO.cs +++ b/src/Build.OM.UnitTests/TransientIO.cs @@ -77,7 +77,7 @@ public string GetAbsolutePath(string relative) var absolute = Path.GetFullPath(Path.IsPathRooted(relative) ? relative : Path.Combine(tempRoot, relative)); if (!IsControled(absolute)) { - throw new ArgumentException(null, nameof(relative)); + throw new ArgumentException("Either the path is invalid or it is not rooted to RootFolder.", nameof(relative)); } return absolute; From 0df9185926625beb3a52e3e79db7c6a7b6333266 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Sat, 8 Jan 2022 15:39:30 +1000 Subject: [PATCH 3/5] Revert CodeAnalysis.ruleset --- eng/CodeAnalysis.ruleset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset index 88f13bb1a08..2078c42fe6c 100644 --- a/eng/CodeAnalysis.ruleset +++ b/eng/CodeAnalysis.ruleset @@ -126,7 +126,7 @@ - + From d0508dc7becd40b5c58c35d0ae432486a079a192 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Sat, 8 Jan 2022 15:50:58 +1000 Subject: [PATCH 4/5] enable warning on CA2208 --- eng/Common.globalconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Common.globalconfig b/eng/Common.globalconfig index fd878420d57..4f5314ab69e 100644 --- a/eng/Common.globalconfig +++ b/eng/Common.globalconfig @@ -373,7 +373,7 @@ dotnet_diagnostic.CA2153.severity = none dotnet_diagnostic.CA2201.severity = none # Instantiate argument exceptions correctly -dotnet_diagnostic.CA2208.severity = suggestion +dotnet_diagnostic.CA2208.severity = warning # Non-constant fields should not be visible dotnet_diagnostic.CA2211.severity = none From 59475193c9870c9dff8cc07ec5a2cd290dc39cf5 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Sat, 8 Jan 2022 15:51:24 +1000 Subject: [PATCH 5/5] Fix remaining occurrences of CA2208 violations --- src/StringTools/InternableString.Simple.cs | 3 ++- src/Tasks/ManifestUtil/TrustInfo.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/StringTools/InternableString.Simple.cs b/src/StringTools/InternableString.Simple.cs index 88126da5c6f..9ef590be148 100644 --- a/src/StringTools/InternableString.Simple.cs +++ b/src/StringTools/InternableString.Simple.cs @@ -20,7 +20,8 @@ public static string AsSpan(this T[] array, int start, int length) { return new string(charArray, start, length); } - throw new ArgumentException(nameof(array)); + + throw new ArgumentException("array is not char array.", nameof(array)); } } } diff --git a/src/Tasks/ManifestUtil/TrustInfo.cs b/src/Tasks/ManifestUtil/TrustInfo.cs index 1652655417d..c8c501b5e8c 100644 --- a/src/Tasks/ManifestUtil/TrustInfo.cs +++ b/src/Tasks/ManifestUtil/TrustInfo.cs @@ -412,7 +412,7 @@ public bool IsFullTrust public PermissionSet PermissionSet { get => GetOutputPermissionSet(); - set => _outputPermissionSet = value ?? throw new ArgumentNullException("PermissionSet cannot be set to null."); + set => _outputPermissionSet = value ?? throw new ArgumentNullException(nameof(value), "PermissionSet cannot be set to null."); } #endif