{"record":{"id":"a975999050a9bdc2","repo":"dotnet/wpf","slug":"sr-datagrid-automationinvokefailed-a97599","errorCode":null,"errorMessage":"SR.DataGrid_AutomationInvokeFailed","messagePattern":"SR\\.DataGrid_AutomationInvokeFailed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridItemAutomationPeer.cs","lineNumber":251,"sourceCode":"                {\n                    if (this.OwningDataGrid.Columns.Count > 0)\n                    {\n                        DataGridCell cell = this.OwningDataGrid.TryFindCell(item, this.OwningDataGrid.Columns[0]);\n                        if (cell != null)\n                        {\n                            this.OwningDataGrid.UnselectAll();\n                            cell.Focus();\n                            success = this.OwningDataGrid.BeginEdit();\n                        }\n                    }\n                }\n            }\n\n            // Invoke on a NewItemPlaceholder row creates a new item.\n            // BeginEdit on a NewItemPlaceholder row returns false.\n            if (!success && !IsNewItemPlaceholder)\n            {\n                throw new InvalidOperationException(SR.DataGrid_AutomationInvokeFailed);\n            }\n        }\n\n        #endregion\n\n        #region IScrollItemProvider\n\n        void IScrollItemProvider.ScrollIntoView()\n        {\n            this.OwningDataGrid.ScrollIntoView(Item);\n        }\n\n        #endregion\n\n        #region ISelectionItemProvider\n\n        bool ISelectionItemProvider.IsSelected\n        {","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/DataGridItemAutomationPeer.cs#L233-L269","documentation":"DataGridItemAutomationPeer.Invoke throws InvalidOperationException when invoking the row neither committed a new item nor the row is not a NewItemPlaceholder. I.e., the DataGrid's BeginEdit/commit attempt on the row failed and the row is an ordinary row, so automation Invoke semantics could not be fulfilled.","triggerScenarios":"Calling the UIA Invoke pattern on a DataGrid row when DataGrid.BeginEdit (or the placeholder's commit) returns false — e.g. the row is read-only, editing is disabled, or a commit validation error blocks it.","commonSituations":"Test automation clicking rows in a read-only DataGrid (IsReadOnly=true) or with no editing commands; validation rules rejecting the commit of a NewItemPlaceholder row.","solutions":["Verify the DataGrid is not read-only (DataGrid.IsReadOnly == false) and the row supports editing before invoking.","Ensure row validation rules pass so BeginEdit/commit succeeds.","For placeholder rows, check that CanUserAddRows is enabled.","Catch InvalidOperationException around the Invoke call and handle non-editable rows explicitly."],"exampleFix":"// before\ninvokePattern.Invoke(); // throws on read-only grid\n// after\nif (!dataGrid.IsReadOnly && dataGrid.CanUserAddRows)\n    invokePattern.Invoke();","handlingStrategy":"try-catch","validationCode":"bool canInvoke = !dataGrid.IsReadOnly && (rowPlaceholder ? dataGrid.CanUserAddRows : true);","typeGuard":null,"tryCatchPattern":"try { invokePattern.Invoke(); }\ncatch (InvalidOperationException) { /* row is not editable; use keyboard/DataGrid API instead */ }","preventionTips":["Check DataGrid.IsReadOnly and CanUserAddRows before automating Invoke","Ensure validation rules allow the edit/commit","Invoke only rows that support editing in the current grid configuration"],"tags":["wpf","uiautomation","datagrid","invoke-pattern"],"backgroundTag":"invalid-state-transition","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"}