dotnet/wpf · error · XamlParseException

Invalid XAML type-name list string; error message produced…

Error message

Invalid XAML type-name list string; error message produced by XamlTypeName.ParseListInternal (e.g. "The string '{0}' is not a valid XAML type name list. Type name lists are comma-delimited lists of types; such as 'x:String, x:Int32'.")

What it means

When the scanner encounters an x:TypeArguments attribute, ReadObjectElement_Object calls XamlTypeName.ParseListInternal to parse the comma-delimited generic type argument list. If parsing fails, ParseListInternal returns null and produces an error message (e.g. "The string '{0}' is not a valid XAML type name list..."), which is thrown as XamlParseException with line/position info. The library throws this because a generic instantiation cannot be constructed without valid type arguments.

Solutions

  1. Write the list in valid XAML form with prefixed names, e.g. x:TypeArguments="sys:String, sys:Int32"
  2. Ensure every referenced prefix (x:, sys:, local:) is declared with xmlns on the element or root
  3. Check comma placement — no trailing commas, no empty items in the list

Example fix

// before
<local:MyGeneric x:TypeArguments="string, int" />
// after (prefixes declared and used)
<local:MyGeneric xmlns:sys="clr-namespace:System;assembly=mscorlib"
                 x:TypeArguments="sys:String, sys:Int32" />
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidTypeArgumentList(string s) => !string.IsNullOrWhiteSpace(s) && s.Split(',').All(t => t.Trim().Contains(':') && !t.Trim().EndsWith(","));

Try / catch

try { LoadXaml(xaml); } catch (System.Xaml.XamlParseException ex) when (ex.Message.Contains("valid XAML type name list")) { FixTypeArguments(ex.LineNumber); throw; }

Prevention

When it happens

Trigger: XAML markup contains x:TypeArguments="..." whose value is not a syntactically valid comma-delimited list of namespace-prefixed type names (missing prefix, bad separators, nested generics written incorrectly, empty entries).

Common situations: Using generic types like Dictionary<TKey,TValue> in XAML with typos in the list; missing xmlns prefix declarations for the argument types; copying type syntax from C# (Dictionary<string, int>) instead of XAML syntax.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/409cd0a1e29aea85. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs:382

            if (IsXDataElement(xmlns, name))
            {
                // If XData don't Enqueue the <x:XData> node.
                // just queue the InnerXml as TEXT (w/ IsTextXML == true).
                // This will advance the "current" xml node to the </x:XData>
                // which will be skipped when we return and the main loop
                // Read()s to the "next" XmlNode.
                ReadInnerXDataSection();
                return true;
            }

            IList<XamlTypeName> typeArgs = null;
            if (_typeArgumentAttribute is not null)
            {
                string error;
                typeArgs = XamlTypeName.ParseListInternal(_typeArgumentAttribute.Value, _parserContext.FindNamespaceByPrefix, out error);
                if (typeArgs is null)
                {
                    throw new XamlParseException(_typeArgumentAttribute.LineNumber, _typeArgumentAttribute.LinePosition, error);
                }
            }

            XamlTypeName typeName = new XamlTypeName(xmlns, name, typeArgs);
            node.Type = _parserContext.GetXamlType(typeName, true);

            // Finish initializing the attributes in the context of the
            // current Element.
            PostprocessAttributes(node);

            if (_scannerStack.Depth > 0)
            {
                // Sub-elements (and Text) are the definition of Content
                _scannerStack.CurrentlyInContent = true;
            }

            if (!node.IsEmptyTag)
            {

View on GitHub (pinned to 81131a70a4)