ReferenceEquals is given a value type, which is boxed into a new object, so the result is always false
What it finds
object.ReferenceEquals compares references. A value of a struct, an int or a bool passed to it is boxed into a fresh object for the call, so two such arguments are never the same reference, even when the values are equal. The rule reports a call where an argument is a numeric, bool or char literal, or a variable whose declared type is one of the built-in value types or DateTime, TimeSpan or Guid.
From the rule's source, reference_equals_value_type.rs.
using System; class Ids{ bool Same(int a, int b) => ReferenceEquals(a, b);tx0 reports: ReferenceEquals is given a int, which is boxed and never the same reference bool Same(object a, object b) => object.ReferenceEquals(a, b); bool Now(DateTime when) => object.ReferenceEquals(when, null);tx0 reports: ReferenceEquals is given a DateTime, which is boxed and never the same reference} 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:reference-equals-value-type" = "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:reference-equals-value-type] reason="..."tx0 explain tx0/csharp:reference-equals-value-type shows the same in the terminal. Found a false positive? Report it.