Rename a class and its methods and a decompiler still reads your event declarations almost verbatim — because a C# event is not one symbol. It is a small cluster of metadata that the compiler wires together for you, and a renamer that treats it as a single name either misses parts of the cluster or breaks the convention that holds it together. Get it wrong and the assembly still verifies but throws MissingMethodException the first time something subscribes; get it right and the event vanishes into the same anonymous soup as everything else.
So the question is concrete: when you rename an event, what exactly are you renaming, and what has to stay pinned so the event still works?
One event, four names
Take the most common form, the field-like event:
public class Document { public event EventHandler Changed; protected void OnChanged() => Changed?.Invoke(this, EventArgs.Empty); } That one line expands, at compile time, into four distinct pieces of metadata:
- an Event table row named
Changed, carrying the event's type (EventHandler); - an
add_Changedaccessor method; - a
remove_Changedaccessor method; - a private, compiler-generated backing delegate field, also named
Changed, that holds the current subscriber list.
The .event metadata directive ties the first three together:
.event [System.Runtime]System.EventHandler Changed { .addon instance void Document::add_Changed(class [System.Runtime]System.EventHandler) .removeon instance void Document::remove_Changed(class [System.Runtime]System.EventHandler) } Under the hood that directive is a row in the Event table plus two MethodSemantics rows, one tagging add_Changed with the AddOn flag and one tagging remove_Changed with RemoveOn, both pointing back at the event. Crucially, those rows reference the methods by token, not by name.
The backing field is where a field-like event actually stores its handlers, and the accessor the compiler writes is thread-safe. Here is the real body of add_Changed — a lock-free Interlocked.CompareExchange loop that combines the new delegate onto the field and retries if another thread beat it:
.method public hidebysig specialname instance void add_Changed(class [System.Runtime]System.EventHandler 'value') cil managed { .locals init (class EventHandler V_0, class EventHandler V_1, class EventHandler V_2) IL_0000: ldarg.0 IL_0001: ldfld class EventHandler Document::Changed IL_0006: stloc.0 IL_0007: ldloc.0 IL_0008: stloc.1 IL_0009: ldloc.1 IL_000a: ldarg.1 IL_000b: call class Delegate Delegate::Combine(class Delegate, class Delegate) IL_0010: castclass class EventHandler IL_0015: stloc.2 IL_0016: ldarg.0 IL_0017: ldflda class EventHandler Document::Changed IL_001c: ldloc.2 IL_001d: ldloc.1 IL_001e: call !!0 Interlocked::CompareExchange<class EventHandler>(!!0&, !!0, !!0) IL_0023: stloc.0 IL_0024: ldloc.0 IL_0025: ldloc.1 IL_0026: bne.un.s IL_0007 IL_0028: ret } The two ldfld/ldflda at IL_0001 and IL_0017 are the accessor's only link to the backing field — by token again. remove_Changed is the mirror image, built on Delegate.Remove.
So "rename the event" is really four coordinated edits, and one invariant: the add/remove/field tokens must keep pointing at the same renamed entities.
An Event row links an add accessor, a remove accessor and a backing field; a rename changes all four names together while the token-based association stays intact
What Nebula actually does
When renaming is enabled, Nebula walks each Event row and renames it as a unit. It picks a new name for the event, renames the two accessors to add_<new> / remove_<new> so the C# naming convention still holds, and renames the backing field to an unrelated short name. It does not have to rewrite the .event directive or the MethodSemantics rows — those are token references, so once the methods are renamed in place, the association still resolves. The Interlocked loop keeps working because its ldfld/ldflda are also token references into the (now renamed) field.
The custom-accessor form is simpler, because there is no compiler field to track:
private EventHandler _handlers; public event EventHandler Changed { add { _handlers += value; } remove { _handlers -= value; } } Here you own the backing field (_handlers), so Nebula renames the event, add_Changed, remove_Changed, and _handlers the same way it renames any field you declared. Same invariant, fewer surprises.
Configuration is the ordinary renaming block — events are renamed along with every other member:
{ "renaming": { "mode": "dictionary", "renameEvents": true, "keep": [ "MyApp.Plugins.IPlugin.*", "MyApp.Api.DocumentEvents::Changed" ] } } nebula protect ./bin/Release/net8.0/App.dll \ --config nebula.config.json \ --out ./protected/ The keep list is the dial that matters for events, and the reason is the next section.
Where it breaks
Renaming an event is safe for everything that reaches it by token — C# code compiled against the same assembly, the .event directive, the accessors' own IL. It breaks everything that reaches the event by its string name. That is a short but important list.
Reflection subscription. This is the same failure class as string-based reflection anywhere:
EventInfo ev = typeof(Document).GetEvent("Changed"); // null after rename ev.AddEventHandler(doc, handler); // NullReferenceException Type.GetEvent("Changed") matches on the Event row's name. Rename the row and the lookup returns null. Anything that subscribes reflectively — a plugin host, a weak-event manager that resolves accessors by name, a serializer wiring up change notifications — stops finding the event. The fix is the keep-list: pin the event by its fully-qualified name, or exclude the whole public contract with the attribute, which also documents the intent in source:
[Obfuscation(Feature = "renaming", Exclude = true)] public event EventHandler Changed; Applied to a type, [Obfuscation(ApplyToMembers = false)] keeps the names of every member on the public surface, events included.
XAML and WPF binding. A {Binding} resolves property names at runtime from strings in the BAML, and INotifyPropertyChanged fires PropertyChanged with a string property name — not the event name, but the same brittleness: if a binding or an ICommand/CanExecuteChanged wiring depends on an event or property being findable by name, renaming it silently breaks the binding. Keep the names on any type that XAML touches.
WinRT events. The Windows Runtime projection uses a different add/remove shape: add_X returns an EventRegistrationToken and remove_X takes one back. If your event is part of a WinRT component's public ABI, those accessors and the event are contract surface — exclude them, exactly as you would any other public API.
Delegates as public API. A delegate type you expose for callers to implement — public delegate void DocumentChangedHandler(object sender, DocChangedArgs e) — is part of your surface. Rename it and a consumer compiled against the old name no longer binds. Keep public delegate types just like public interfaces; rename only the delegates that never leave your own code.
Takeaway
A C# event is four coordinated metadata names bound by token, and the whole value of that design, for a renamer, is that the binding is immune to renaming — Nebula changes the event, both accessors and the backing field in one consistent step, keeps the add_/remove_ convention, and the .event association and the Interlocked loop keep working because they never depended on the names in the first place. What does depend on the names is every by-name consumer: reflection, XAML, WinRT ABI, and public delegates. Protect your own IP by renaming aggressively and pinning that narrow by-name surface with a keep-list or [Obfuscation]. See Nebula.NET and the documentation.
