{"record":{"id":"9818c210bdf3226f","repo":"dotnet/wpf","slug":"sr-nomulticasthandlers","errorCode":null,"errorMessage":"SR.NoMulticastHandlers","messagePattern":"SR\\.NoMulticastHandlers","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ValueChangedEventManager.cs","lineNumber":87,"sourceCode":"        /// <summary>\n        /// Remove a listener to the given source's event.\n        /// </summary>\n        public static void RemoveListener(object source, IWeakEventListener listener, PropertyDescriptor pd)\n        {\n            ArgumentNullException.ThrowIfNull(source);\n            ArgumentNullException.ThrowIfNull(listener);\n\n            CurrentManager.PrivateRemoveListener(source, listener, pd);\n        }\n\n        /// <summary>\n        /// Add a handler for the given source's event.\n        /// </summary>\n        public static void AddHandler(object source, EventHandler<ValueChangedEventArgs> handler, PropertyDescriptor pd)\n        {\n            ArgumentNullException.ThrowIfNull(handler);\n            if (!handler.HasSingleTarget)\n                throw new NotSupportedException(SR.NoMulticastHandlers);\n\n            CurrentManager.PrivateAddHandler(source, handler, pd);\n        }\n\n        /// <summary>\n        /// Remove a handler for the given source's event.\n        /// </summary>\n        public static void RemoveHandler(object source, EventHandler<ValueChangedEventArgs> handler, PropertyDescriptor pd)\n        {\n            ArgumentNullException.ThrowIfNull(handler);\n            if (!handler.HasSingleTarget)\n                throw new NotSupportedException(SR.NoMulticastHandlers);\n\n            CurrentManager.PrivateRemoveHandler(source, handler, pd);\n        }\n\n        #endregion Public Methods\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/ValueChangedEventManager.cs#L69-L105","documentation":"ValueChangedEventManager.AddHandler requires a delegate with exactly one target; multicast (combined) delegates are rejected with NotSupportedException(SR.NoMulticastHandlers). The weak-event manager tracks one target per handler and cannot correctly unsubscribe combined delegates.","triggerScenarios":"Calling ValueChangedEventManager.AddHandler(source, handler, pd) where handler was built with Delegate.Combine / '+=' on a local delegate variable, giving it multiple invocation targets.","commonSituations":"Reusing a shared multicast event-handler field for weak-event registration; refactoring from normal CLR events (which allow multicast) to weak events without splitting handlers.","solutions":["Register each handler method individually (one AddHandler call per method)","Split the combined delegate into GetInvocationList() and call AddHandler for each single-target delegate","Use a lambda or method group that references only one target"],"exampleFix":"// before\nEventHandler<ValueChangedEventArgs> h = OnA; h += OnB;\nValueChangedEventManager.AddHandler(source, h, pd); // throws\n// after\nValueChangedEventManager.AddHandler(source, OnA, pd);\nValueChangedEventManager.AddHandler(source, OnB, pd);","handlingStrategy":"validation","validationCode":"if (handler == null) throw new ArgumentNullException(nameof(handler));\nif (handler.GetInvocationList().Length > 1) throw new ArgumentException(\"Use single-target delegates with ValueChangedEventManager\");","typeGuard":"bool HasSingleTarget(Delegate d) => d is { } && d.GetInvocationList().Length == 1;","tryCatchPattern":"if (handler.GetInvocationList().Length == 1)\n    ValueChangedEventManager.AddHandler(source, handler, pd);\nelse\n    foreach (EventHandler<ValueChangedEventArgs> h in handler.GetInvocationList())\n        ValueChangedEventManager.AddHandler(source, h, pd);","preventionTips":["Never '+=' delegates before weak-event registration","One AddHandler call per handler method","Remember weak event managers differ from CLR multicast events"],"tags":["wpf","weak-events","eventmanager","multicast"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}