From 779b3945b11033dfb5a811378281766beb3a97d2 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Thu, 30 Dec 2021 13:17:28 +1000 Subject: [PATCH 1/4] CA1835 Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' --- eng/CodeAnalysis.ruleset | 2 +- src/Shared/CommunicationsUtilities.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset index 2078c42fe6c..bc271faec76 100644 --- a/eng/CodeAnalysis.ruleset +++ b/eng/CodeAnalysis.ruleset @@ -105,7 +105,7 @@ - + diff --git a/src/Shared/CommunicationsUtilities.cs b/src/Shared/CommunicationsUtilities.cs index 487080a3dff..b5e7ae076f0 100644 --- a/src/Shared/CommunicationsUtilities.cs +++ b/src/Shared/CommunicationsUtilities.cs @@ -463,7 +463,7 @@ internal static async Task ReadAsync(Stream stream, byte[] buffer, int byte int totalBytesRead = 0; while (totalBytesRead < bytesToRead) { - int bytesRead = await stream.ReadAsync(buffer, totalBytesRead, bytesToRead - totalBytesRead); + int bytesRead = await stream.ReadAsync(buffer.AsMemory(totalBytesRead, bytesToRead - totalBytesRead), new CancellationToken()); if (bytesRead == 0) { return totalBytesRead; From 8c98b9552f6dbedae944d36aa6be9badd23b4fd3 Mon Sep 17 00:00:00 2001 From: Lachlan Ennis <2433737+elachlan@users.noreply.github.com> Date: Mon, 3 Jan 2022 10:16:19 +1000 Subject: [PATCH 2/4] Update src/Shared/CommunicationsUtilities.cs Co-authored-by: Sam Harwell --- src/Shared/CommunicationsUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shared/CommunicationsUtilities.cs b/src/Shared/CommunicationsUtilities.cs index b5e7ae076f0..4053f5d84a5 100644 --- a/src/Shared/CommunicationsUtilities.cs +++ b/src/Shared/CommunicationsUtilities.cs @@ -463,7 +463,7 @@ internal static async Task ReadAsync(Stream stream, byte[] buffer, int byte int totalBytesRead = 0; while (totalBytesRead < bytesToRead) { - int bytesRead = await stream.ReadAsync(buffer.AsMemory(totalBytesRead, bytesToRead - totalBytesRead), new CancellationToken()); + int bytesRead = await stream.ReadAsync(buffer.AsMemory(totalBytesRead, bytesToRead - totalBytesRead), CancellationToken.None); if (bytesRead == 0) { return totalBytesRead; From 4967f4ae65f951e8bbb5661ea36ffde839158b16 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Sat, 8 Jan 2022 14:46:08 +1000 Subject: [PATCH 3/4] 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 bc271faec76..2078c42fe6c 100644 --- a/eng/CodeAnalysis.ruleset +++ b/eng/CodeAnalysis.ruleset @@ -105,7 +105,7 @@ - + From 6925aeae8ee2c3376c717a1e959e26c465230c17 Mon Sep 17 00:00:00 2001 From: elachlan <2433737+elachlan@users.noreply.github.com> Date: Sat, 8 Jan 2022 14:46:53 +1000 Subject: [PATCH 4/4] enable warning on CA1835 --- eng/Common.globalconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Common.globalconfig b/eng/Common.globalconfig index fd878420d57..3590395a013 100644 --- a/eng/Common.globalconfig +++ b/eng/Common.globalconfig @@ -310,7 +310,7 @@ dotnet_diagnostic.CA1833.severity = warning dotnet_diagnostic.CA1834.severity = suggestion # Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' -dotnet_diagnostic.CA1835.severity = suggestion +dotnet_diagnostic.CA1835.severity = warning # Prefer IsEmpty over Count dotnet_diagnostic.CA1836.severity = suggestion