dotnet/wpf · error · ArgumentException
SR.CustomDictionaryNullItem
Error message
SR.CustomDictionaryNullItem
What it means
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.
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.
Example fix
// before
Uri uri = new Uri(configPath); // or null
lexicons.Add(uri); // throws on null
// after
if (Uri.TryCreate(configPath, UriKind.Absolute, out var uri))
lexicons.Add(uri); Defensive patterns
Strategy: validation
Validate before calling
if (uri != null)
lexicons.Add(uri); Type guard
static bool IsValidDictionaryUri(Uri item) => item != null;
Try / catch
try
{
lexicons.Add(item);
}
catch (ArgumentException)
{
// null item supplied; skip and log
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- SR.CustomDictionaryItemAlreadyExists
- SR.CustomDictionarySourcesUnsupportedURI
- annotation component
- ArgumentException: path
- ArgumentException: relativeTo
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/26c753145a58b047.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/CustomDictionarySources.cs:338
// Private Methods
//
//------------------------------------------------------
#region Private Methods
/// <summary>
/// Makes sure Uri is of supported kind. Throws exception for unsupported URI type.
/// Supported URI types [please keep this list updated]
/// 1. Local path
/// 2. Relative path
/// 3. UNC path
/// 4. Pack URI
/// </summary>
/// <param name="item"></param>
private static void ValidateUri(Uri item)
{
if (item == null)
{
throw new ArgumentException(SR.CustomDictionaryNullItem);
}
if (item.IsAbsoluteUri)
{
if (!(item.IsUnc || item.IsFile || MS.Internal.IO.Packaging.PackUriHelper.IsPackUri(item)))
{
throw new NotSupportedException(SR.CustomDictionarySourcesUnsupportedURI);
}
}
}
#endregion Private Methods
//------------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
private readonly List<Uri> _uriList;View on GitHub (pinned to 81131a70a4)