{"record":{"id":"f99905c346125793","repo":"stride3d/stride","slug":"reset-is-not-supported-on-the-tag-collection","errorCode":null,"errorMessage":"Reset is not supported on the tag collection.","messagePattern":"Reset is not supported on the tag collection\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs","lineNumber":679,"sourceCode":"            if (Directory.Assets.Any(x => string.Equals(x.Name, newName, StringComparison.InvariantCultureIgnoreCase) && x != this))\n            {\n                error = string.Format(Tr._p(\"Message\", \"Unable to rename asset to '{0}' because an asset with the same name exists in the same directory\"), newName);\n                return false;\n            }\n            if (string.IsNullOrWhiteSpace(newName))\n            {\n                error = Tr._p(\"Message\", \"Unable to rename asset with an empty name\");\n                return false;\n            }\n            error = null;\n            return true;\n        }\n\n        private void TagsCollectionChanged(object sender, [NotNull] NotifyCollectionChangedEventArgs e)\n        {\n            if (e.Action == NotifyCollectionChangedAction.Reset)\n            {\n                throw new InvalidOperationException(\"Reset is not supported on the tag collection.\");\n            }\n            if (e.OldItems != null)\n            {\n                foreach (string oldItem in e.OldItems)\n                {\n                    assetItem.Asset.Tags.Remove(oldItem);\n                }\n            }\n            if (e.NewItems != null)\n            {\n                foreach (string newItem in e.NewItems)\n                {\n                    assetItem.Asset.Tags.Add(newItem);\n                }\n            }\n        }\n\n        private void CreateDerivedAsset()","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs#L661-L697","documentation":"The Tags view model subscribes to its tag collection's CollectionChanged and translates Add/Remove events into edits on the underlying asset. A Reset action (the whole collection being cleared/replaced at once, e.g. via Clear() or a new assignment) carries no item-level information, so the handler throws InvalidOperationException instead of silently desynchronizing the asset's Tags.","triggerScenarios":"Calling Clear() on the exposed tag collection, or bulk-replacing it in a way that raises NotifyCollectionChangedAction.Reset instead of granular Add/Remove changes.","commonSituations":"Code bulk-clearing tags before re-adding them; data-binding frameworks firing Reset; test code that assigns a fresh collection.","solutions":["Remove tags one by one instead of calling Clear(): iterate a snapshot and Remove each item.","If you must clear many tags, wrap individual removals in a single undo/redo transaction so behavior and history stay correct.","Never reassign or rebuild the exposed collection; mutate the existing one."],"exampleFix":"// before\nvm.Tags.Clear();\n// after\nusing (vm.Session.UndoRedoService.CreateTransaction())\n    foreach (var tag in vm.Tags.ToList())\n        vm.Tags.Remove(tag);","handlingStrategy":"try-catch","validationCode":"// avoid Reset: remove items individually\nforeach (var tag in vm.Tags.ToList()) vm.Tags.Remove(tag);","typeGuard":null,"tryCatchPattern":"try { MutateTags(vm, action); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Reset\")) { logger.Error(ex, \"Use item-by-item tag removal instead of Clear()/Reset\"); }","preventionTips":["Never call Clear() or reassign the exposed tag collection","Wrap bulk tag edits in a single undo/redo transaction","Prefer Remove per item so CollectionChanged carries item details"],"tags":["assets","tags","collection-reset","inotifycollectionchanged"],"backgroundTag":"unsupported-operation","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"}