dotnet/reactive · error · InvalidOperationException
Could not find static event
Error message
Could not find static event '{0}' on type '{1}'. What it means
GetEventMethods, the reflection core behind FromEventPattern, throws InvalidOperationException when no static event with the given name exists on the target type. Since no target object was supplied, the library looks up the event with BindingFlags for static members via GetEventEx and finds nothing.
Solutions
- Verify the event name spelling against the actual type declaration (events are passed as strings and not compile-checked)
- If the event is an instance event, use the FromEventPattern overload that takes a target object instead
- Use nameof(Source.EventName) to get a compile-checked name
Example fix
// before var obs = AsyncObservable.FromEventPattern<object, EventArgs>(typeof(Source), "Progres"); // typo, and event is instance // after var src = new Source(); var obs = AsyncObservable.FromEventPattern<object, EventArgs>(src, nameof(Source.Progress));
Defensive patterns
Strategy: validation
Validate before calling
var ev = typeof(EventSource).GetEvent(eventName, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
if (ev is null) throw new ArgumentException($"Static event '{eventName}' not found on {typeof(EventSource)}.", nameof(eventName)); Type guard
static bool HasStaticEvent(Type t, string name) => t.GetEvent(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) is not null;
Try / catch
try { var obs = AsyncObservable.FromEventPattern<TSender, TEventArgs>(type, eventName); }
catch (InvalidOperationException ex) { log.LogError(ex, "Static event {Event} missing on {Type}", eventName, type); throw; } Prevention
- Use nameof for compile-checked event names
- Check BindingFlags.FlattenHierarchy for inherited static events
- List available events with type.GetEvents() when unsure
When it happens
Trigger: Calling the static FromEventPattern(Type, string) overload with an event name that is actually an instance event, a misspelled name, or an event that lives on a base type/interface not considered by GetEventEx.
Common situations: Typo in event name string (no compile-time check because events are passed as strings), renamed event after a library upgrade, assuming the event is static when it is an instance event.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Could not find instance event
- Missing add method on event.
- Missing remove method on event.
- The add method of an event should take one parameter.
- The remove method of an event should take one parameter.
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/c1a8ad411a575136.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/FromEventPattern.cs:270
return default;
});
return new ValueTask<IAsyncDisposable>(dispose);
});
}
return SynchronizeEvents(res, scheduler);
}
private static (MethodInfo addMethod, MethodInfo removeMethod, Type delegateType, bool isWinRT) GetEventMethods<TSender, TEventArgs>(Type targetType, object target, string eventName)
{
EventInfo e;
if (target == null)
{
e = targetType.GetEventEx(eventName, isStatic: true);
if (e == null)
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Could not find static event '{0}' on type '{1}'.", eventName, targetType.FullName));
}
else
{
e = targetType.GetEventEx(eventName, isStatic: false);
if (e == null)
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Could not find instance event '{0}' on type '{1}'.", eventName, targetType.FullName));
}
var addMethod = e.GetAddMethod();
var removeMethod = e.GetRemoveMethod();
if (addMethod == null)
throw new InvalidOperationException("Missing add method on event.");
if (removeMethod == null)
throw new InvalidOperationException("Missing remove method on event.");
var psa = addMethod.GetParameters();
if (psa.Length != 1)View on GitHub (pinned to 94b5d5ab91)