{"record":{"id":"26c753145a58b047","repo":"dotnet/wpf","slug":"sr-customdictionarynullitem","errorCode":null,"errorMessage":"SR.CustomDictionaryNullItem","messagePattern":"SR\\.CustomDictionaryNullItem","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CustomDictionarySources.cs","lineNumber":338,"sourceCode":"        //  Private Methods\n        //\n        //------------------------------------------------------\n        #region Private Methods\n\n        /// <summary>\n        /// Makes sure Uri is of supported kind. Throws exception for unsupported URI type.\n        /// Supported URI types [please keep this list updated]\n        /// 1. Local path\n        /// 2. Relative path\n        /// 3. UNC path\n        /// 4. Pack URI\n        /// </summary>\n        /// <param name=\"item\"></param>\n        private static void ValidateUri(Uri item)\n        {\n            if (item == null)\n            {\n                throw new ArgumentException(SR.CustomDictionaryNullItem);\n            }\n            if (item.IsAbsoluteUri)\n            {\n                if (!(item.IsUnc || item.IsFile || MS.Internal.IO.Packaging.PackUriHelper.IsPackUri(item)))\n                {\n                    throw new NotSupportedException(SR.CustomDictionarySourcesUnsupportedURI);\n                }\n            }\n        }\n        #endregion Private Methods\n        \n        //------------------------------------------------------\n        //\n        //  Private Fields\n        //\n        //------------------------------------------------------\n        #region Private Fields\n        private readonly List<Uri> _uriList;","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CustomDictionarySources.cs#L320-L356","documentation":"ValidateUri, used by the custom-dictionary Uri collection on Insert/Add/construction, throws ArgumentException(SR.CustomDictionaryNullItem) when a null Uri is supplied. The collection only accepts real, valid dictionary source Uris, and null entries cannot be stored.","triggerScenarios":"Calling Add/Insert on the custom dictionary Uri collection, or constructing CustomDictionarySources with a list containing a null Uri (e.g. from a null entry in configuration or a failed Uri.TryCreate).","commonSituations":"Building the dictionary list from config/app settings where a blank path yields null, or code that assumes Uri parsing always succeeds and passes the unassigned variable.","solutions":["Guard with if (uri != null) before adding; skip or log null entries.","Validate that the value producing the Uri is non-empty and parse successfully with Uri.TryCreate before constructing the collection.","Fix the configuration/source so it does not emit empty dictionary entries.","Catch ArgumentException during bulk add to skip nulls, if acceptable."],"exampleFix":"// before\nUri uri = new Uri(configPath); // or null\nlexicons.Add(uri); // throws on null\n// after\nif (Uri.TryCreate(configPath, UriKind.Absolute, out var uri))\n    lexicons.Add(uri);","handlingStrategy":"validation","validationCode":"if (uri != null)\n    lexicons.Add(uri);","typeGuard":"static bool IsValidDictionaryUri(Uri item) => item != null;","tryCatchPattern":"try\n{\n    lexicons.Add(item);\n}\ncatch (ArgumentException)\n{\n    // null item supplied; skip and log\n}","preventionTips":["Use Uri.TryCreate and only add on success","Filter nulls from config-driven dictionary lists","Assert non-null at the boundary where dictionary paths are read"],"tags":["wpf","spellcheck","null-argument","dictionary"],"backgroundTag":"null-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"}