{"record":{"id":"480713a6d4e20cd0","repo":"stride3d/stride","slug":"provided-collections-don-t-match-an-existing-scope","errorCode":null,"errorMessage":"Provided collections don't match an existing scope","messagePattern":"Provided collections don't match an existing scope","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/Services/SelectionService.cs","lineNumber":136,"sourceCode":"        }\n\n        /// <summary>\n        /// Unregisters collections of selected objects from the <see cref=\"SelectionService\"/>.\n        /// </summary>\n        /// <param name=\"collections\"></param>\n        /// <remarks>The order of the collections to unregister must match the order used when registering with <see cref=\"RegisterSelectionScope\"/>.</remarks>\n        public void UnregisterSelectionScope(params INotifyCollectionChanged[] collections)\n        {\n            foreach (var scope in scopes)\n            {\n                if (ArrayExtensions.ArraysReferenceEqual(scope.Collections, collections))\n                {\n                    UnregisterSelectionScope(scope);\n                    return;\n                }\n            }\n\n            throw new ArgumentException($\"Provided {nameof(collections)} don't match an existing scope\", nameof(collections));\n        }\n\n        /// <summary>\n        /// Unregisters a collection scope selected objects from the <see cref=\"SelectionService\"/>.\n        /// </summary>\n        /// <param name=\"scope\">The selection scope to unregister.</param>\n        public void UnregisterSelectionScope([NotNull] SelectionScope scope)\n        {\n            if (scope == null) throw new ArgumentNullException(nameof(scope));\n            foreach (var collection in scope.Collections)\n                collection.CollectionChanged -= CollectionChanged;\n            scopes.Remove(scope);\n            // Update history to let it know about this collection\n            foreach (var operation in stack.RetrieveAllTransactions().SelectMany(x => x.Operations).OfType<SelectionOperation>())\n            {\n                foreach (var collection in scope.Collections)\n                    operation.UnregisterCollection(collection);\n            }","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/Services/SelectionService.cs#L118-L154","documentation":"UnregisterSelectionScope iterates the registered scopes looking for one whose tracked collections match the supplied collections; if none matches, it throws ArgumentException stating the provided collections don't match an existing scope.","triggerScenarios":"Calling UnregisterSelectionScope with a collection (or collection set) that was never registered via RegisterSelectionScope, or with a copy/rebuilt collection instance that no longer matches the registered reference, or after the scope was already unregistered.","commonSituations":"Double-unregister on teardown; passing a LINQ-enumerated copy instead of the original collection; view recreated (new collection instances) while the old scope registration held the originals.","solutions":["Keep and pass the exact same collection instances used at RegisterSelectionScope time","Register the scope before attempting to unregister; skip unregister if never registered","Make unregister idempotent by checking registration state first"],"exampleFix":"// before\nselectionService.UnregisterSelectionScope(items); // items is a reconstructed collection\n// after\nif (registeredCollections != null)\n    selectionService.UnregisterSelectionScope(registeredCollections); // same reference as registered","handlingStrategy":"validation","validationCode":"if (registeredScopes.All(s => !s.Collections.SequenceEqual(collections))) return; // not registered; nothing to unregister","typeGuard":"bool IsScopeRegistered(IEnumerable<object> collections) => /* check against the service's registered scope collections */ false;","tryCatchPattern":"try { selectionService.UnregisterSelectionScope(collections); } catch (ArgumentException) { /* scope never registered or already removed; ignore */ }","preventionTips":["Store the original collection references used at registration and reuse them for unregistration","Make unregister calls idempotent and guarded","Avoid LINQ projections/copies when passing collections to scope APIs"],"tags":["argument-exception","selection","state"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}