{"record":{"id":"708ece6469bb7b41","repo":"dotnet/wpf","slug":"sr-cannotmovetounknownposition-listcollectionview","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/ListCollectionView.cs","lineNumber":2518,"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\n        /// <summary>\n        /// Create, filter and sort the local index array.\n        /// called from Refresh(), override in derived classes as needed.\n        /// </summary>\n        /// <param name=\"list\">new ILIst to associate this view with</param>\n        /// <returns>new local array to use for this view</returns>\n        private void PrepareLocalArray()","sourceCodeStart":2500,"sourceCodeEnd":2536,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/ListCollectionView.cs#L2500-L2536","documentation":"A Move notification was raised with NewStartingIndex < 0, meaning the source collection reported an unknown destination index. ListCollectionView throws InvalidOperationException (SR.CannotMoveToUnknownPosition) because it cannot position the moved item.","triggerScenarios":"The bound collection raises NotifyCollectionChangedAction.Move with a single NewItems item but NewStartingIndex == -1 or negative, typically from calling CollectionChanged manually or from a Move implementation that lost track of the index.","commonSituations":"Hand-raised Move events using NotifyCollectionChangedAction.Reset-style unknown-index (-1) conventions; ported collection code that always passes -1 for position.","solutions":["Fix the Move event source to pass the actual zero-based destination index as NewStartingIndex.","If the destination is unknown, raise Reset instead of Move.","Catch InvalidOperationException around the update and call Refresh() to resynchronize the view."],"exampleFix":"// before\nOnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, item, -1, oldIndex));\n// after\nOnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, item, newIndex, oldIndex));","handlingStrategy":"validation","validationCode":"if (args.Action == NotifyCollectionChangedAction.Move && args.NewStartingIndex < 0) { /* invalid move; use Reset or fix index */ }","typeGuard":null,"tryCatchPattern":"try { /* handle move */ } catch (InvalidOperationException) { view.Refresh(); }","preventionTips":["Always pass the real zero-based destination index for Move","Use Reset when the destination index is unknown","Test move/reorder paths of custom collections before binding"],"tags":["wpf","collection-view","move-index"],"backgroundTag":"value-out-of-range","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"}