A lambda or anonymous method is removed from an event, which removes nothing
What it finds
button.Click -= (s, e) => Save(); creates a new delegate that was never subscribed, so nothing is removed and the handler added earlier stays. Keep the delegate in a variable or use a method, and remove that.
From the rule's source, lambda_unsubscribe.rs.
using System; class Form{ public event EventHandler Click; private EventHandler handler; void Wire() { Click += (s, e) => Save(); Click -= (s, e) => Save();tx0 reports: removing a new lambda from an event removes nothing Click -= delegate { Save(); };tx0 reports: removing a new lambda from an event removes nothing Click -= handler; } void Save() { }} 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:lambda-unsubscribe" = "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:lambda-unsubscribe] reason="..."tx0 explain tx0/csharp:lambda-unsubscribe shows the same in the terminal. Found a false positive? Report it.