{"record":{"id":"c63038030d6f4f8e","repo":"dotnet/wpf","slug":"mappingparseerror-scanner-start-token-token","errorCode":null,"errorMessage":"MappingParseError(_scanner.Start, token, _token)","messagePattern":"MappingParseError\\(_scanner\\.Start, token, _token\\)","errorType":"exception","errorClass":"MappingParseError","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs","lineNumber":2708,"sourceCode":"                public readonly string Ident;\n\n                public MappingParseError(int offset, char expected, char received)\n                {\n                    Offset = offset;\n                    Expected = expected;\n                    Received = received;\n                }\n\n                public MappingParseError(int offset, char expected, char received, string ident)\n                    : this(offset, expected, received)\n                {\n                    Ident = ident;\n                }\n            }\n\n            private void Error(char token)\n            {\n                throw new MappingParseError(_scanner.Start, token, _token);\n            }\n\n            private void Error(string ident)\n            {\n                throw new MappingParseError(_scanner.Start, MappingScanner.Ident, _token, ident);\n            }\n        }\n        #endregion\n\n        private string ResolveAttributeNamespaceURI(string prefix, string name, string parentURI)\n        {\n            string attribNamespaceURI;\n            if(!String.IsNullOrEmpty(prefix))\n            {\n                attribNamespaceURI = XmlReader.LookupNamespace(prefix);\n            }\n            else\n            {","sourceCodeStart":2690,"sourceCodeEnd":2726,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs#L2690-L2726","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the mapping string to the canonical form 'clr-namespace:<Namespace>;assembly=<AssemblyName>'.","Check for typos in separators (use '=' after 'assembly', ';' between clauses) and stray whitespace or quotes.","Validate dynamically constructed mapping strings before passing them to ParserContext / XamlParser."],"exampleFix":"// before\nctx.XmlnsDictionary[\"my\"] = \"clr-namespace:MyApp.Controls;assembly:MyApp\";\n// after\nctx.XmlnsDictionary[\"my\"] = \"clr-namespace:MyApp.Controls;assembly=MyApp\";","handlingStrategy":"validation","validationCode":"static bool IsValidClrNamespaceMapping(string s) =>\n    s.StartsWith(\"clr-namespace:\") &&\n    s.Split(';').All(part => part.Contains(':')) &&\n    !s.Contains(\"assembly:\"); // '=' required, not ':' after 'assembly'","typeGuard":null,"tryCatchPattern":"try { parser.Parse(xml); }\ncatch (XamlParseException ex) { /* inspect ex for mapping errors at scanner.Start */ }","preventionTips":["Use string interpolation with named parts when building clr-namespace strings: $\"clr-namespace:{ns};assembly={asm}\".","Copy mapping strings from working XAML files rather than typing separators by hand.","Unit-test any code that constructs namespace mapping strings dynamically."],"tags":["wpf","xaml","parse-error","namespace-mapping"],"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"}