{"record":{"id":"28bf8aefb3d07fde","repo":"dotnet/wpf","slug":"underlyingnamescope","errorCode":null,"errorMessage":"underlyingNameScope","messagePattern":"underlyingNameScope","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/NameScopeDictionary.cs","lineNumber":33,"sourceCode":"    // of HybridDictionary to match the performance semantics of 3.0 for the time being\n    // Note that the IEnumerable<T> uses KeyValuePair<string, object>\n    // This means that we need to create KeyValuePairs on the fly\n    // The other option would be to just use IEnumerable (or change the HybridDictionary to Dictionary<K,V>)\n    // but I opted for generic usability for now since this shouldn't be a common hot path.\n    internal class NameScopeDictionary : INameScopeDictionary\n    {\n        private HybridDictionary _nameMap;\n        private INameScope _underlyingNameScope;\n        private FrugalObjectList<string> _names;\n\n        public NameScopeDictionary()\n        {\n        }\n\n        public NameScopeDictionary(INameScope underlyingNameScope)\n        {\n            _names = new FrugalObjectList<string>();\n            _underlyingNameScope = underlyingNameScope ?? throw new ArgumentNullException(nameof(underlyingNameScope));\n        }\n\n        public void RegisterName(string name, object scopedElement)\n        {\n            ArgumentNullException.ThrowIfNull(name);\n\n            ArgumentNullException.ThrowIfNull(scopedElement);\n\n            if (name.Length == 0)\n                throw new ArgumentException(SR.NameScopeNameNotEmptyString);\n\n            if (!NameValidationHelper.IsValidIdentifierName(name))\n            {\n                throw new ArgumentException(SR.Format(SR.NameScopeInvalidIdentifierName, name));\n            }\n\n            if (_underlyingNameScope is not null)\n            {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/NameScopeDictionary.cs#L15-L51","documentation":"The NameScopeDictionary(INameScope underlyingNameScope) constructor requires an underlying INameScope to delegate name registration to. Passing null leaves the dictionary without its backing scope, so it throws ArgumentNullException via the ?? throw pattern.","triggerScenarios":"Constructing NameScopeDictionary with a null INameScope argument, typically when a backing NameScope failed to initialize or was passed by mistake.","commonSituations":"WPF/XAML infrastructure wiring where the underlying NameScope is null because the object is not yet fully initialized; custom code instantiating NameScopeDictionary directly for tests.","solutions":["Create or obtain the actual NameScope/INameScope instance before constructing NameScopeDictionary","Guard the call site so the underlying scope is initialized lazily if it can be null","Pass a default NameScope instance if a real one is unavailable"],"exampleFix":"// before\nvar dict = new NameScopeDictionary(underlyingNameScope); // underlyingNameScope is null\n// after\nvar dict = new NameScopeDictionary(underlyingNameScope ?? new NameScope());","handlingStrategy":"type-guard","validationCode":"if (underlyingNameScope is null) throw new InvalidOperationException(\"Underlying INameScope must be initialized\");\nvar dict = new NameScopeDictionary(underlyingNameScope);","typeGuard":"static bool CanBuild(INameScope s) => s is not null;","tryCatchPattern":"try { var dict = new NameScopeDictionary(scope); }\ncatch (ArgumentNullException ex) { /* scope was null */ }","preventionTips":["Initialize the backing NameScope before constructing NameScopeDictionary","Avoid constructing NameScopeDictionary during partial object initialization","Null-check scope dependencies in factory code"],"tags":["wpf","system-xaml","namescope","argumentnull"],"backgroundTag":"missing-required-argument","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"}