{"record":{"id":"5f5b0dccbc90e49d","repo":"dotnet/reactive","slug":"strings-linq-could-not-find-static-event","errorCode":null,"errorMessage":"Strings_Linq.COULD_NOT_FIND_STATIC_EVENT","messagePattern":"Strings_Linq\\.COULD_NOT_FIND_STATIC_EVENT","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs","lineNumber":33,"sourceCode":"            return (TDelegate)(object)method.CreateDelegate(typeof(TDelegate), o);\n        }\n\n        public static Delegate CreateDelegate(Type delegateType, object o, MethodInfo method)\n        {\n            return method.CreateDelegate(delegateType, o);\n        }\n\n#if HAS_TRIMMABILITY_ATTRIBUTES\n    [RequiresUnreferencedCode(Constants_Core.EventReflectionTrimIncompatibilityMessage)]\n#endif\n        public static void GetEventMethods<TSender, TEventArgs>(Type targetType, object? target, string eventName, out MethodInfo addMethod, out MethodInfo removeMethod, out Type delegateType, out bool isWinRT)\n        {\n            EventInfo? e;\n\n            if (target == null)\n            {\n                e = targetType.GetEvent(eventName, BindingFlags.Public | BindingFlags.Static)\n                    ?? throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings_Linq.COULD_NOT_FIND_STATIC_EVENT, eventName, targetType.FullName));\n            }\n            else\n            {\n                e = targetType.GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance)\n                    ?? throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings_Linq.COULD_NOT_FIND_INSTANCE_EVENT, eventName, targetType.FullName));\n            }\n\n            addMethod = e.GetAddMethod() ?? throw new InvalidOperationException(Strings_Linq.EVENT_MISSING_ADD_METHOD);\n            removeMethod = e.GetRemoveMethod() ?? throw new InvalidOperationException(Strings_Linq.EVENT_MISSING_REMOVE_METHOD);\n\n            var psa = addMethod.GetParameters();\n            if (psa.Length != 1)\n            {\n                throw new InvalidOperationException(Strings_Linq.EVENT_ADD_METHOD_SHOULD_TAKE_ONE_PARAMETER);\n            }\n\n            var psr = removeMethod.GetParameters();\n            if (psr.Length != 1)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs#L15-L51","documentation":"ReflectionUtils.GetEventMethods resolves an event by name via reflection. When the target is null (static event lookup), it searches public static events on targetType and throws InvalidOperationException 'Could not find static event <name> on <type>' when no such event exists. This powers Observable.FromEventPattern.","triggerScenarios":"Observable.FromEventPattern(target: null, eventName, targetType) with an eventName that is not a public static event on targetType, or a misspelled event name.","commonSituations":"Typos in event name strings; event exists but is instance-level while null target forces static lookup; event declared non-public; type moved/renamed the event in a newer version.","solutions":["Verify the event name spelling and that it is declared public static on targetType.","If the event is an instance event, pass the target instance instead of null.","Check targetType.FullName at runtime (print it) to confirm the intended type is being reflected."],"exampleFix":"// before\nObservable.FromEventPattern(null, \"Changed\", typeof(Config)); // event is instance-level\n// after\nvar cfg = new Config();\nObservable.FromEventPattern(cfg, \"Changed\", typeof(Config));","handlingStrategy":"validation","validationCode":"var evt = targetType.GetEvent(eventName, BindingFlags.Public | BindingFlags.Static);\nif (evt == null) throw new ArgumentException($\"Static event '{eventName}' not found on {targetType.FullName}\");\nObservable.FromEventPattern(null, eventName, targetType);","typeGuard":"static bool HasStaticEvent(Type t, string name) => t.GetEvent(name, BindingFlags.Public | BindingFlags.Static) != null;","tryCatchPattern":"try { Observable.FromEventPattern(null, eventName, targetType); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"static event\")) { /* correct name or target */ }","preventionTips":["Prefer the generic FromEventPattern<TDelegate, TArgs> overloads with method-group +=/-= to get compile-time checks.","Keep event names as constants rather than string literals.","Confirm static vs instance before choosing null vs non-null target."],"tags":["reflection","event","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}