A lock takes an object created on the spot, so it excludes nobody
What it finds
lock (new object()) locks a fresh object that no other thread can ever see: every thread gets its own lock, and the block runs concurrently as if unlocked.
From the rule's source, lock_on_new_object.rs.
class Counter{ private int count; private readonly object gate = new(); void Add() { lock (new object())tx0 reports: this lock is a new object each time, so it excludes no other thread { count++; } lock (gate) { count++; } }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/csharp:lock-on-new-object" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:lock-on-new-object] reason="..."tx0 explain tx0/csharp:lock-on-new-object shows the same in the terminal. Found a false positive? Report it.