{"record":{"id":"d25e4dd9c51eeb73","repo":"dotnet/wpf","slug":"sr-atleastonepropertymustbespecified","errorCode":null,"errorMessage":"SR.AtLeastOnePropertyMustBeSpecified","messagePattern":"SR\\.AtLeastOnePropertyMustBeSpecified","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/Automation.cs","lineNumber":222,"sourceCode":"        /// Called by a client to add a listener for property changed events.\n        /// </summary>\n        /// <param name=\"element\">Element on which to listen for property changed events.</param>\n        /// <param name=\"scope\">Specifies whether to listen to property changes events on the specified element, and/or its ancestors and children.</param>\n        /// <param name=\"eventHandler\">Callback object to call when a specified property change occurs.</param>\n        /// <param name=\"properties\">Params array of properties to listen for changes in.</param>\n        public static void AddAutomationPropertyChangedEventHandler(\n            AutomationElement element,            // reference element for listening to the event\n            TreeScope scope,                   // scope to listen to\n            AutomationPropertyChangedEventHandler eventHandler,    // callback object\n            params AutomationProperty [] properties           // listen for changes to these properties\n            )\n        {\n            ArgumentNullException.ThrowIfNull(element);\n            ArgumentNullException.ThrowIfNull(eventHandler);\n            ArgumentNullException.ThrowIfNull(properties);\n            if (properties.Length == 0)\n            {\n                throw new ArgumentException( SR.AtLeastOnePropertyMustBeSpecified );\n            }\n\n            // Check that no properties are interpreted properties\n            // If more interpreted properties are identified add a mapping of\n            // on interpreted properties to the real property that raises events.\n            foreach (AutomationProperty property in properties)\n            {\n                ArgumentNullException.ThrowIfNull(property, nameof(properties));\n            }\n\n            // Add a client-side listener for for this event request\n            EventListener l = new EventListener(AutomationElement.AutomationPropertyChangedEvent, scope, properties, CacheRequest.CurrentUiaCacheRequest);\n            ClientEventManager.AddListener(element, eventHandler, l);\n        }\n\n        /// <summary>\n        /// Called by a client to remove a listener for property changed events.\n        /// </summary>","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/Automation.cs#L204-L240","documentation":"Automation.AddAutomationPropertyChangedEventHandler requires a non-empty properties array since there is nothing to listen to otherwise. Passing an empty AutomationProperty[] throws ArgumentException with SR.AtLeastOnePropertyMustBeSpecified. Null arguments are separately rejected by ArgumentNullException.ThrowIfNull.","triggerScenarios":"Calling Automation.AddAutomationPropertyChangedEventHandler(element, handler, scope, new AutomationProperty[0]) or an array initialized without any properties.","commonSituations":"Building the properties array dynamically (filtering a list) and passing the empty result; copying sample code with a placeholder empty array; configuration selecting zero properties.","solutions":["Ensure at least one AutomationProperty is in the array before calling (e.g. AutomationElement.NameProperty, IsEnabledProperty)","Add a guard in your code that skips registration (or logs) when the property list is empty","Validate that the dynamic property-selection logic actually yields properties"],"exampleFix":"// before\nvar props = selected.Select(p => p.Property).ToArray();\nAutomation.AddAutomationPropertyChangedEventHandler(el, handler, TreeScope.Element, props);\n// after\nvar props = selected.Select(p => p.Property).ToArray();\nif (props.Length > 0)\n{\n    Automation.AddAutomationPropertyChangedEventHandler(el, handler, TreeScope.Element, props);\n}","handlingStrategy":"validation","validationCode":"if (properties == null || properties.Length == 0)\n    throw new InvalidOperationException(\"At least one AutomationProperty is required\");","typeGuard":null,"tryCatchPattern":"try { Automation.AddAutomationPropertyChangedEventHandler(el, handler, scope, props); }\ncatch (ArgumentException) { log.Warn(\"No properties selected; skipping registration\"); }","preventionTips":["Guard dynamic property lists for emptiness before subscribing","Never pass placeholder empty arrays in test scaffolding"],"tags":["uiautomation","wpf","empty-array","argument"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}