Skip to main content

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

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.

if (conditionA) {
    DoSomething();
}
else if (conditionB) {
    if (conditionA) { // CRR0022
        DoSomethingElse();
    }
}

Consider the flowchart of the code snippet given above.

Analyzers_CRR0022

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.