You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/fundamentals/code-analysis/quality-rules/ca1806.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "CA1806: Do not ignore method results (code analysis)"
3
3
description: "Learn about code analysis rule CA1806: Do not ignore method results"
4
-
ms.date: 06/08/2022
4
+
ms.date: 10/30/2025
5
5
f1_keywords:
6
6
- CA1806
7
7
- DoNotIgnoreMethodResults
@@ -32,6 +32,7 @@ There are several possible reasons for this warning:
32
32
- A method that creates and returns a new string is called and the new string is never used.
33
33
- A COM or P/Invoke method returns a `HRESULT` or error code that's never used.
34
34
- A language-integrated query (LINQ) method returns a result that's never used.
35
+
- A `[Pure]` method is called and the return value is never used.
35
36
36
37
## Rule description
37
38
@@ -41,7 +42,7 @@ Strings are immutable and methods such as <xref:System.String.ToUpper%2A?display
41
42
42
43
Ignoring `HRESULT` or an error code can lead to low-resource conditions or unexpected behavior in error conditions.
43
44
44
-
LINQ methods are known to not have side effects, and the result should not be ignored.
45
+
LINQ methods and methods annotated with <xref:System.Diagnostics.Contracts.PureAttribute>are known to not have side effects, and the result should not be ignored.
45
46
46
47
## How to fix violations
47
48
@@ -57,7 +58,7 @@ If method A calls method B but does not use the `HRESULT` or error code that the
57
58
58
59
-or-
59
60
60
-
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.
61
+
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.
61
62
62
63
## When to suppress warnings
63
64
@@ -122,7 +123,7 @@ The following example fixes the violation by assigning the result of <xref:Syste
122
123
The following example shows a method that doesn't use an object that it creates.
123
124
124
125
> [!NOTE]
125
-
> This violation cannot be reproduced in Visual Basic.
126
+
> This violation can't be reproduced in Visual Basic.
0 commit comments