Skip to content
Latchkey

C# "CS0201: only assignment, call, increment ... can be used as a statement" in CI

CS0201 means a line is a bare expression with no effect the compiler will accept as a statement. A comparison, a property access, or a stray expression on its own line triggers it - usually a typo where == was meant to be =, or a discarded result.

What this error means

The build fails with CS0201 pointing at a line that evaluates something but does nothing with it. It reproduces deterministically.

dotnet
Calc.cs(14,9): error CS0201: Only assignment, call, increment, decrement, await,
and new object expressions can be used as a statement

Common causes

A comparison used instead of an assignment

Writing x == 5; (comparison) where x = 5; (assignment) was intended produces a value-only statement the compiler rejects.

A bare member access or expression

A line like list.Count; reads a value and discards it, which is not a valid statement.

How to fix it

Make the line do something

  1. Change == to = if an assignment was intended.
  2. Assign the expression to a variable, or discard it explicitly with _ =.
  3. Delete the line if it was leftover and rebuild.
C#
_ = list.Count; // explicit discard if the side-effect-free read is intentional

How to prevent it

  • Enable analyzers that flag value-discarding expression statements.
  • Review diffs for accidental == vs = swaps.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →