From d7676bd86f10823f2e657c08b32efe708e225dde Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:40:11 -0700 Subject: [PATCH 1/3] Update CA1806 with Pure methods --- .../code-analysis/quality-rules/ca1806.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1806.md b/docs/fundamentals/code-analysis/quality-rules/ca1806.md index cb34fc9d91d65..b219feebcf9a1 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1806.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1806.md @@ -1,7 +1,7 @@ --- title: "CA1806: Do not ignore method results (code analysis)" description: "Learn about code analysis rule CA1806: Do not ignore method results" -ms.date: 06/08/2022 +ms.date: 10/30/2025 f1_keywords: - CA1806 - DoNotIgnoreMethodResults @@ -32,6 +32,7 @@ There are several possible reasons for this warning: - A method that creates and returns a new string is called and the new string is never used. - A COM or P/Invoke method returns a `HRESULT` or error code that's never used. - A language-integrated query (LINQ) method returns a result that's never used. +- A `[Pure]` method is called and the value the method returns is never used. ## Rule description @@ -41,7 +42,7 @@ Strings are immutable and methods such as are known to not have side effects, and the result should not be ignored. ## How to fix violations @@ -57,7 +58,11 @@ If method A calls method B but does not use the `HRESULT` or error code that the -or- -If a LINQ method A calls method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. +If method A calls a LINQ method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. + +-or- + +If method A calls a pure method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. ## When to suppress warnings @@ -122,7 +127,7 @@ The following example fixes the violation by assigning the result of [!NOTE] -> This violation cannot be reproduced in Visual Basic. +> This violation can't be reproduced in Visual Basic. :::code language="csharp" source="snippets/csharp/all-rules/ca1806.cs" id="snippet3"::: From 6c1cc86d0f0c6163cfa27d6097f06fa3a7e04846 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:47:46 -0700 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/fundamentals/code-analysis/quality-rules/ca1806.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1806.md b/docs/fundamentals/code-analysis/quality-rules/ca1806.md index b219feebcf9a1..775bcadaf7553 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1806.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1806.md @@ -32,7 +32,7 @@ There are several possible reasons for this warning: - A method that creates and returns a new string is called and the new string is never used. - A COM or P/Invoke method returns a `HRESULT` or error code that's never used. - A language-integrated query (LINQ) method returns a result that's never used. -- A `[Pure]` method is called and the value the method returns is never used. +- A `[Pure]` method is called and the return value is never used. ## Rule description @@ -58,12 +58,7 @@ If method A calls method B but does not use the `HRESULT` or error code that the -or- -If method A calls a LINQ method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. - --or- - -If method A calls a pure method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. - +If method A calls a LINQ or pure method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. ## When to suppress warnings Do not suppress a warning from this rule unless the act of creating the object serves some purpose. From 10331f5f1ce7fc1d15b7fa1894443800a64e0dac Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:56:34 -0700 Subject: [PATCH 3/3] Update docs/fundamentals/code-analysis/quality-rules/ca1806.md --- docs/fundamentals/code-analysis/quality-rules/ca1806.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1806.md b/docs/fundamentals/code-analysis/quality-rules/ca1806.md index 775bcadaf7553..91163cad653d8 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1806.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1806.md @@ -59,6 +59,7 @@ If method A calls method B but does not use the `HRESULT` or error code that the -or- If method A calls a LINQ or pure method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. + ## When to suppress warnings Do not suppress a warning from this rule unless the act of creating the object serves some purpose.