Equals, GetHashCode, ToString, Dispose, an equality operator, an implicit conversion or a static constructor throws
What it finds
Some members are called by code that does not expect them to fail: collections call Equals and GetHashCode on every lookup, debuggers and loggers call ToString, using calls Dispose while another exception may be on its way, an implicit conversion is invisible at the call site, and an exception in a static constructor makes the whole type unusable for the rest of the process. The rule reports throw new ...; NotImplementedException and NotSupportedException are left alone, since they mark a member that is not written yet or not offered, and so are rethrows, throw null in reference assemblies and throws of helper calls that mark unreachable code.
From the rule's source, throw_in_identity_member.rs.
using System; class Money{ public override bool Equals(object other) { if (other == null) { throw new ArgumentNullException(nameof(other));tx0 reports: Equals throws } return false; } public override int GetHashCode() => throw new NotImplementedException(); public override string ToString() => throw new InvalidOperationException();tx0 reports: ToString throws public void Check() => throw new InvalidOperationException();} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:throw-in-identity-member" = "warning"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:throw-in-identity-member] reason="..."tx0 explain tx0/csharp:throw-in-identity-member shows the same in the terminal. Found a false positive? Report it.