{"record":{"id":"ded84a9af41065b8","repo":"dotnet/wpf","slug":"formatexception-error-from-xamltypename-parselist","errorCode":null,"errorMessage":"FormatException(error from XamlTypeName.ParseList)","messagePattern":"FormatException\\(error from XamlTypeName\\.ParseList\\)","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs","lineNumber":116,"sourceCode":"            XamlTypeName result = ParseInternal(typeName, namespaceResolver.GetNamespace, out error);\n            if (result is null)\n            {\n                throw new FormatException(error);\n            }\n\n            return result;\n        }\n\n        public static IList<XamlTypeName> ParseList(string typeNameList, IXamlNamespaceResolver namespaceResolver)\n        {\n            ArgumentNullException.ThrowIfNull(typeNameList);\n            ArgumentNullException.ThrowIfNull(namespaceResolver);\n\n            string error;\n            IList<XamlTypeName> result = ParseListInternal(typeNameList, namespaceResolver.GetNamespace, out error);\n            if (result is null)\n            {\n                throw new FormatException(error);\n            }\n\n            return result;\n        }\n\n        public static bool TryParse(string typeName, IXamlNamespaceResolver namespaceResolver,\n            out XamlTypeName result)\n        {\n            ArgumentNullException.ThrowIfNull(typeName);\n            ArgumentNullException.ThrowIfNull(namespaceResolver);\n\n            result = ParseInternal(typeName, namespaceResolver.GetNamespace, out _);\n            return (result is not null);\n        }\n\n        public static bool TryParseList(string typeNameList, IXamlNamespaceResolver namespaceResolver,\n            out IList<XamlTypeName> result)\n        {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs#L98-L134","documentation":"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.","triggerScenarios":"Calling XamlTypeName.ParseList(typeNameList, namespaceResolver) where the comma-delimited string contains any invalid entry: empty element between commas, malformed name, or unresolvable prefix.","commonSituations":"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.","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."],"exampleFix":"// before\nvar list = XamlTypeName.ParseList(\"x:String,,x:Int32\", ns); // FormatException (empty element)\n// after\nif (XamlTypeName.TryParseList(\"x:String,x:Int32\", ns, out var parsed, out var error)) { /* use parsed */ }","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(typeNameList)) throw new ArgumentException(\"List is empty\");\nif (!XamlTypeName.TryParseList(typeNameList, nsResolver, out var list, out var error))\n    throw new FormatException($\"Invalid XAML type name list: {error}\");","typeGuard":"bool IsValidXamlTypeList(string s, IXamlNamespaceResolver ns) =>\n    !string.IsNullOrWhiteSpace(s) && XamlTypeName.TryParseList(s, ns, out _, out _);","tryCatchPattern":"try { var list = XamlTypeName.ParseList(typeNameList, nsResolver); }\ncatch (FormatException ex) { /* report which list failed; fall back to per-item TryParse for diagnostics */ }","preventionTips":["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."],"tags":["xaml","parsing","format"],"backgroundTag":"invalid-argument-format","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"}