Skip to content

Precision gap: CommandManager.RequerySuggested (weak-referenced WPF static event) flagged as a hard error #223

Description

@PhysShell

Found by: the issue #201 oracle sweep, docs/notes/oracle-sweep-2026-07-10.md; catalogued as docs/notes/field-notes-patterns.md entry 17.

The pattern

EventHandler requerySuggestedHandler; // we need to keep the event handler instance
                                       // alive because CommandManager.RequerySuggested
                                       // uses weak references
requerySuggestedHandler = OnRequerySuggested;
CommandManager.RequerySuggested += requerySuggestedHandler;   // never -=, and that's fine

System.Windows.Input.CommandManager.RequerySuggested is WPF's own answer to the classic "static event pins every subscriber forever" trap — it's implemented internally over weak references, so a subscriber is not kept alive by the subscription. The in-repo comment even explains the field exists to keep the handler from being collected prematurely — the opposite of the leak concern. Never unsubscribing is the normal, intended usage.

Own.NET tiers a subscription to a provably static source as a hard error ("its source is a static (process-lived) event source") — the systematically wrong verdict for this one named event.

Evidence

  • AvalonEdit ICSharpCode.AvalonEdit/Editing/ImeSupport.cs:34-47

Suggested direction (not prescriptive)

Add a small named allowlist (starting with System.Windows.Input.CommandManager.RequerySuggested) of BCL/WPF static events known to be implemented over weak references, exempted from the static-source hard-error tier. Extend the list only when another confirmed sibling is found — not a general "static sources are fine" relaxation.

Scope

No analyzer code changed as part of the sweep — this issue tracks the fix as its own unit of work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions