{"record":{"id":"00e6c123bb194642","repo":"dotnet/wpf","slug":"sr-cannotmovetounknownposition","errorCode":null,"errorMessage":"SR.CannotMoveToUnknownPosition","messagePattern":"SR\\.CannotMoveToUnknownPosition","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs","lineNumber":2450,"sourceCode":"                    if (e.NewItems.Count != 1)\n                        throw new NotSupportedException(SR.RangeActionsNotSupported);\n                    break;\n\n                case NotifyCollectionChangedAction.Remove:\n                    if (e.OldItems.Count != 1)\n                        throw new NotSupportedException(SR.RangeActionsNotSupported);\n                    break;\n\n                case NotifyCollectionChangedAction.Replace:\n                    if (e.NewItems.Count != 1 || e.OldItems.Count != 1)\n                        throw new NotSupportedException(SR.RangeActionsNotSupported);\n                    break;\n\n                case NotifyCollectionChangedAction.Move:\n                    if (e.NewItems.Count != 1)\n                        throw new NotSupportedException(SR.RangeActionsNotSupported);\n                    if (e.NewStartingIndex < 0)\n                        throw new InvalidOperationException(SR.CannotMoveToUnknownPosition);\n                    break;\n\n                case NotifyCollectionChangedAction.Reset:\n                    break;\n\n                default:\n                    throw new NotSupportedException(SR.Format(SR.UnexpectedCollectionChangeAction, e.Action));\n            }\n        }\n\n        /// <summary>\n        /// Helper to raise a PropertyChanged event  />).\n        /// </summary>\n        private void OnPropertyChanged(string propertyName)\n        {\n            OnPropertyChanged(new PropertyChangedEventArgs(propertyName));\n        }\n","sourceCodeStart":2432,"sourceCodeEnd":2468,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs#L2432-L2468","documentation":"A Move notification with NewStartingIndex < 0 (an 'unknown' position, value -1) throws InvalidOperationException(SR.CannotMoveToUnknownPosition) in ValidateCollectionChangedEventArgs. The view cannot apply a move when the notification does not specify the destination index.","triggerScenarios":"Source collection raises NotifyCollectionChangedAction.Move with NewStartingIndex == -1 (the 'unknown index' sentinel), typically constructed with a constructor that omits the index or a custom notifier that fails to set it.","commonSituations":"Hand-rolled collection code calling the ObservableCollection.Move overload incorrectly or building MoveEventArgs without an index; moving an item whose position could not be determined (e.g. after a search that returned -1) and passing that -1 through.","solutions":["Ensure the Move notification always carries a valid NewStartingIndex >= 0.","Verify the source index exists before calling Move; never propagate a -1 from a failed IndexOf into Move.","If the destination is genuinely unknown, use Reset + Refresh instead of Move."],"exampleFix":"// before\nint dest = list.IndexOf(item); // -1 if not found\nlist.Move(list.IndexOf(x), dest); // throws CannotMoveToUnknownPosition\n\n// after\nint dest = list.IndexOf(item);\nif (dest >= 0) list.Move(oldIndex, dest);","handlingStrategy":"validation","validationCode":"int dest = list.IndexOf(item);\nif (dest >= 0 && oldIndex >= 0) list.Move(oldIndex, dest);","typeGuard":null,"tryCatchPattern":"try { list.Move(oldIndex, dest); } catch (InvalidOperationException) { view.Refresh(); }","preventionTips":["Never pass a -1 sentinel index into Move","Validate IndexOf results before moving","Always set NewStartingIndex when constructing Move event args"],"tags":["wpf","collection-view","move-operation","invalid-index"],"backgroundTag":"invalid-argument-value","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"}