{"record":{"id":"51f44c2597a26680","repo":"AvaloniaUI/Avalonia","slug":"dictionary-reset-not-supported","errorCode":null,"errorMessage":"Dictionary reset not supported","messagePattern":"Dictionary reset not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Controls/ResourceDictionary.cs","lineNumber":73,"sourceCode":"                {\n                    _mergedDictionaries = new AvaloniaList<IResourceProvider>();\n                    _mergedDictionaries.ResetBehavior = ResetBehavior.Remove;\n                    _mergedDictionaries.ForEachItem(\n                        x =>\n                        {\n                            if (Owner is not null)\n                            {\n                                x.AddOwner(Owner);\n                            }\n                        },\n                        x =>\n                        {\n                            if (Owner is not null)\n                            {\n                                x.RemoveOwner(Owner);\n                            }\n                        }, \n                        () => throw new NotSupportedException(\"Dictionary reset not supported\"));\n                }\n\n                return _mergedDictionaries;\n            }\n        }\n\n        public IDictionary<ThemeVariant, IThemeVariantProvider> ThemeDictionaries\n        {\n            get\n            {\n                if (_themeDictionary == null)\n                {\n                    _themeDictionary = new AvaloniaDictionary<ThemeVariant, IThemeVariantProvider>(2);\n                    _themeDictionary.ForEachItem(\n                        (_, x) =>\n                        {\n                            if (Owner is not null)\n                            {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Controls/ResourceDictionary.cs#L55-L91","documentation":"Thrown as NotSupportedException by the reset callback of ResourceDictionary.MergedDictionaries when the underlying AvaloniaList is reset (cleared wholesale). MergedDictionaries tracks per-item add/remove to propagate owner notifications, but a bulk reset is not supported because it cannot be reconciled incrementally with the owner.","triggerScenarios":"Calling ResourceDictionary.MergedDictionaries.Clear() or assigning a new collection that triggers the ForEachItem reset callback (the third Action parameter at line 73). Any operation causing AvaloniaList.ForEachItem's reset handler to fire.","commonSituations":"Code attempts MergedDictionaries.Clear() to rebuild the merged dictionary set at runtime. Reassigning or resetting the collection via reflection or a binding. Theme/Dictionary swap logic that clears instead of removing items one by one.","solutions":["Remove dictionaries individually (RemoveAt / Remove) instead of calling Clear() on MergedDictionaries.","Rebuild by removing each existing entry in a loop, then adding the new ones.","If you need a wholesale swap, replace the entire ResourceDictionary or Styles collection rather than clearing the merged list."],"exampleFix":"// before\nresources.MergedDictionaries.Clear(); // throws NotSupportedException\n// after\nwhile (resources.MergedDictionaries.Count > 0)\n    resources.MergedDictionaries.RemoveAt(resources.MergedDictionaries.Count - 1);","handlingStrategy":"validation","validationCode":"// never call Clear(); remove individually\nwhile (resourceDictionary.MergedDictionaries.Count > 0)\n    resourceDictionary.MergedDictionaries.RemoveAt(0);","typeGuard":null,"tryCatchPattern":"try { resourceDictionary.MergedDictionaries.Clear(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Dictionary reset\"))\n{ /* fall back to individual removal loop */ }","preventionTips":["Never call Clear() on MergedDictionaries; remove entries one by one.","For wholesale swaps, replace the entire ResourceDictionary or Styles.","Document the no-reset constraint for any code that manipulates merged dictionaries."],"tags":["resource-dictionary","merged-dictionaries","notsupported","styling"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}