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 statementCommon 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
- Change
==to=if an assignment was intended. - Assign the expression to a variable, or discard it explicitly with
_ =. - Delete the line if it was leftover and rebuild.
C#
_ = list.Count; // explicit discard if the side-effect-free read is intentionalHow to prevent it
- Enable analyzers that flag value-discarding expression statements.
- Review diffs for accidental
==vs=swaps.
Related guides
C# "CS1002: ; expected" in CIFix C# "CS1002: ; expected" in CI - a missing statement terminator, usually from an incomplete line or a merg…
C# "CS1003: Syntax error, X expected" in CIFix C# "CS1003: Syntax error, X expected" in CI - the parser expected a specific token (comma, brace, paren)…
C# "CS0120: an object reference is required for the non-static member" in CIFix C# "CS0120: An object reference is required for the non-static field, method, or property M" in CI - an i…