Back to Devexpress

CRR0022 - Unreachable conditional code block (a similar condition in the else branch)

coderushforroslyn-118200-static-code-analysis-analyzers-library-crr0022-unreachable-conditional-code-block-a-similar-condition-in-the-else-branch.md

latest1.2 KB
Original Source

CRR0022 - Unreachable conditional code block (a similar condition in the else branch)

  • Feb 28, 2025

This analyzer detects conditional statements that always evaluate to false because of the conditional statement above. A possible example is shown in the code snippet below.

csharp
if (conditionA) {
    DoSomething();
}
else if (conditionB) {
    if (conditionA) { // CRR0022
        DoSomethingElse();
    }
}
vb
If conditionA Then
    DoSomething()
ElseIf conditionB Then
    If conditionA Then ' CRR0022
        DoSomethingElse()
    End If
End If

Consider the flowchart of the code snippet given above.

If you trace the program flow, you will see that the highlighted branch is never reached. This happens because the conditionA was previously checked to be false , and the second check of the same condition will also evaluate to false.

To fix this, remove the second conditional statement or change its conditional expression so that it differs from the conditionA.

See Also

Suppress Analyzers