dotnet/wpf · error · FormatException
FormatException(error from XamlTypeName.ParseList)
Error message
FormatException(error from XamlTypeName.ParseList)
What it means
XamlTypeName.ParseList parses a comma-separated list of XAML type names; when any element fails the grammar check, ParseListInternal returns null and the public ParseList throws a FormatException carrying the parser's error message. It exists so batch parsing fails loudly rather than silently returning a partial list.
Solutions
- Fix the offending element in the list so every comma-separated token is a valid XAML type name.
- Switch to XamlTypeName.TryParseList to get the error message without an exception.
- Validate each element individually with TryParse to pinpoint which entry is bad.
- Ensure prefixes used in the list are registered in the IXamlNamespaceResolver.
Example fix
// before
var list = XamlTypeName.ParseList("x:String,,x:Int32", ns); // FormatException (empty element)
// after
if (XamlTypeName.TryParseList("x:String,x:Int32", ns, out var parsed, out var error)) { /* use parsed */ } Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(typeNameList)) throw new ArgumentException("List is empty");
if (!XamlTypeName.TryParseList(typeNameList, nsResolver, out var list, out var error))
throw new FormatException($"Invalid XAML type name list: {error}"); Type guard
bool IsValidXamlTypeList(string s, IXamlNamespaceResolver ns) =>
!string.IsNullOrWhiteSpace(s) && XamlTypeName.TryParseList(s, ns, out _, out _); Try / catch
try { var list = XamlTypeName.ParseList(typeNameList, nsResolver); }
catch (FormatException ex) { /* report which list failed; fall back to per-item TryParse for diagnostics */ } Prevention
- Validate each comma-separated element with TryParse before batch parsing.
- Avoid empty list entries; trim whitespace and filter empty tokens at the source.
- Generate lists programmatically instead of manual string editing.
When it happens
Trigger: Calling XamlTypeName.ParseList(typeNameList, namespaceResolver) where the comma-delimited string contains any invalid entry: empty element between commas, malformed name, or unresolvable prefix.
Common situations: Parsing generic type argument lists (e.g. 'x:String,x:Int32') where one element was edited or truncated; splitting input on the wrong delimiter and passing fragments; user input in designer/serialization tooling.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- FormatException(error from XamlTypeName.Parse)
- SR.Format(SR.LengthFormatError, span.ToString())
- ' ' is not a valid XAML member name.
- Invalid XAML type-name list string; error message produced…
- MappingParseError(_scanner.Start, MappingScanner.Ident…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ded84a9af41065b8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs:116
XamlTypeName result = ParseInternal(typeName, namespaceResolver.GetNamespace, out error);
if (result is null)
{
throw new FormatException(error);
}
return result;
}
public static IList<XamlTypeName> ParseList(string typeNameList, IXamlNamespaceResolver namespaceResolver)
{
ArgumentNullException.ThrowIfNull(typeNameList);
ArgumentNullException.ThrowIfNull(namespaceResolver);
string error;
IList<XamlTypeName> result = ParseListInternal(typeNameList, namespaceResolver.GetNamespace, out error);
if (result is null)
{
throw new FormatException(error);
}
return result;
}
public static bool TryParse(string typeName, IXamlNamespaceResolver namespaceResolver,
out XamlTypeName result)
{
ArgumentNullException.ThrowIfNull(typeName);
ArgumentNullException.ThrowIfNull(namespaceResolver);
result = ParseInternal(typeName, namespaceResolver.GetNamespace, out _);
return (result is not null);
}
public static bool TryParseList(string typeNameList, IXamlNamespaceResolver namespaceResolver,
out IList<XamlTypeName> result)
{View on GitHub (pinned to 81131a70a4)