JetBrains Rider 2026.1 Help

Code inspection: Event unsubscription via anonymous delegate

This inspection reports an attempt to unsubscribe from an event by using a new anonymous delegate. That unsubscribe call does not remove the original handler, because the new lambda or anonymous method is a different delegate instance.

Example

publisher.Changed += (s, e) => Console.WriteLine("Changed"); publisher.Changed -= (s, e) => Console.WriteLine("Changed");
EventHandler handler = (s, e) => Console.WriteLine("Changed"); publisher.Changed += handler; publisher.Changed -= handler;

Quick-fix

There is no dedicated quick-fix for this inspection. A typical correction is to store the delegate instance and use the same variable for both subscription and unsubscription.

01 April 2026