dotnet/wpf · error · MappingParseError

MappingParseError(_scanner.Start, token, _token)

Error message

MappingParseError(_scanner.Start, token, _token)

What it means

The MappingScanner's Error(char) helper throws MappingParseError when scanning an XmlnsDefinitionWithAssembly/CLR-namespace mapping string encounters a character that is not valid at the current position of the mapping grammar (e.g. unexpected separator or terminator). It carries the scanner start position, the offending token, and the current token.

Solutions

  1. Fix the mapping string to the canonical form 'clr-namespace:<Namespace>;assembly=<AssemblyName>'.
  2. Check for typos in separators (use '=' after 'assembly', ';' between clauses) and stray whitespace or quotes.
  3. Validate dynamically constructed mapping strings before passing them to ParserContext / XamlParser.

Example fix

// before
ctx.XmlnsDictionary["my"] = "clr-namespace:MyApp.Controls;assembly:MyApp";
// after
ctx.XmlnsDictionary["my"] = "clr-namespace:MyApp.Controls;assembly=MyApp";
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidClrNamespaceMapping(string s) =>
    s.StartsWith("clr-namespace:") &&
    s.Split(';').All(part => part.Contains(':')) &&
    !s.Contains("assembly:"); // '=' required, not ':' after 'assembly'

Try / catch

try { parser.Parse(xml); }
catch (XamlParseException ex) { /* inspect ex for mapping errors at scanner.Start */ }

Prevention

When it happens

Trigger: A clr-namespace / assembly mapping string (e.g. in XmlnsDefinition attributes or ParserContext xml namespace mappings) contains malformed syntax — missing '=', stray characters, unterminated identifiers — parsed by XamlReaderHelper's mapping scanner.

Common situations: Typos in clr-namespace strings like 'clr-namespace:MyNs;assembly=MyAsm' (missing assembly name, wrong separator like ';assembly:' or a stray space/quote), dynamically built mapping strings with formatting errors.

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/c63038030d6f4f8e. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs:2708

                public readonly string Ident;

                public MappingParseError(int offset, char expected, char received)
                {
                    Offset = offset;
                    Expected = expected;
                    Received = received;
                }

                public MappingParseError(int offset, char expected, char received, string ident)
                    : this(offset, expected, received)
                {
                    Ident = ident;
                }
            }

            private void Error(char token)
            {
                throw new MappingParseError(_scanner.Start, token, _token);
            }

            private void Error(string ident)
            {
                throw new MappingParseError(_scanner.Start, MappingScanner.Ident, _token, ident);
            }
        }
        #endregion

        private string ResolveAttributeNamespaceURI(string prefix, string name, string parentURI)
        {
            string attribNamespaceURI;
            if(!String.IsNullOrEmpty(prefix))
            {
                attribNamespaceURI = XmlReader.LookupNamespace(prefix);
            }
            else
            {

View on GitHub (pinned to 81131a70a4)