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
19 changes: 18 additions & 1 deletion docs/fundamentals/code-analysis/style-rules/ide0059.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "IDE0059"
description: "Learn about code analysis style rule IDE0059."
ms.date: 12/13/2023
ms.date: 01/05/2026
f1_keywords:
- IDE0059
- csharp_style_unused_value_assignment_preference
Expand Down Expand Up @@ -55,6 +55,23 @@ You can take one of the following actions to fix this violation:
int v = Compute2();
```

## Known limitations

This rule doesn't work in certain code contexts. The analyzer fails to flag unnecessary value assignments in the following scenarios:

- Assignments inside `try` or `catch` blocks.
- Assignments inside `using` statement blocks.
- Variables assigned within lambda expressions or delegate bodies.
- Variables in the presence of expression trees (`Expression<Func<T>>`).

These limitations are tracked in the following GitHub issues:

- [IDE0059 is not always reported](https://github.com/dotnet/roslyn/issues/52292)
- [Detection of IDE0059 not working within try/catch statements](https://github.com/dotnet/roslyn/issues/65220)
- [IDE0059 not raised inside a code block with using keyword](https://github.com/dotnet/roslyn/issues/74219)
- [IDE0059 doesn't work with expression trees](https://github.com/dotnet/roslyn/issues/80033)
- [Remove unused variable/values (parent issue)](https://github.com/dotnet/roslyn/issues/75737)

## Options

The options for this specify whether to prefer the use of a discard or an unused local variable:
Expand Down