Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/fundamentals/code-analysis/quality-rules/ca1806.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 return value is never used.

## Rule description

Expand All @@ -41,7 +42,7 @@ Strings are immutable and methods such as <xref:System.String.ToUpper%2A?display

Ignoring `HRESULT` or an error code can lead to low-resource conditions or unexpected behavior in error conditions.

LINQ methods are known to not have side effects, and the result should not be ignored.
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.

## How to fix violations

Expand All @@ -57,7 +58,7 @@ 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 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

Expand Down Expand Up @@ -122,7 +123,7 @@ The following example fixes the violation by assigning the result of <xref:Syste
The following example shows a method that doesn't use an object that it creates.

> [!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":::

Expand Down