{"record":{"id":"34084993afec6add","repo":"dotnet/wpf","slug":"mappingparseerror-scanner-start-mappingscanner-ident-token","errorCode":null,"errorMessage":"MappingParseError(_scanner.Start, MappingScanner.Ident, _token, ident)","messagePattern":"MappingParseError\\(_scanner\\.Start, MappingScanner\\.Ident, _token, ident\\)","errorType":"exception","errorClass":"MappingParseError","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs","lineNumber":2713,"sourceCode":"                    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            {\n                // if the prefix was \"\" then\n                // 1) normal properties resolve to the parent Tag namespace.\n                // 2) Attached properties resolve to the \"\" default namespace.\n#if !NETFX\n                if (!name.Contains('.'))","sourceCodeStart":2695,"sourceCodeEnd":2731,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlReaderHelper.cs#L2695-L2731","documentation":"A MappingParseError thrown by XamlReaderHelper's private Error(ident) helper when the mapping scanner fails to parse an identifier in a mapping/prefix declaration (e.g. xmlns:prefix='clr-namespace:...' processing instructions). The XAML loader could not read the expected identifier token while processing mapping directives, so it aborts parsing.","triggerScenarios":"Calling XamlReader.Load/XamlReader parse flows on XAML whose mapping PI (<?Mapping ...?>) or clr-namespace/xmlns declarations contain a malformed or missing identifier where the MappingScanner expected an Ident token.","commonSituations":"Hand-written or generated XAML with typos in clr-namespace names, missing assembly= parts, stray characters in xmlns mappings, or programmatically constructed XAML strings produced by tools emitting invalid mapping syntax.","solutions":["Fix the mapping/namespace declaration in the XAML so it contains a valid identifier (e.g. clr-namespace:MyNs;assembly=MyAssembly).","Check the exact position reported by the error (scanner Start/token) to find the malformed character or missing token.","If XAML is generated at runtime, validate/escape namespace strings before embedding them in the XAML.","If using the Mapping PI, ensure required parts (ClrNamespace, Assembly) are present and well-formed."],"exampleFix":"// before\n<?Mapping XmlNamespace='ui' ClrNamespace='My.App.UI;' ?>\n// after\n<?Mapping XmlNamespace='ui' ClrNamespace='My.App.UI' Assembly='My.App' ?>","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(xaml) || !System.Text.RegularExpressions.Regex.IsMatch(xaml, \"clr-namespace:[A-Za-z_][A-Za-z0-9_.]*\")) throw new FormatException(\"Mapping declaration is malformed; expected clr-namespace:Name;assembly=Asm\");","typeGuard":null,"tryCatchPattern":"try { return (T)XamlReader.Parse(xaml); } catch (XamlParseException ex) { log.Error($\"Mapping error at {ex.LinePosition}: {ex.Message}\"); throw; }","preventionTips":["Validate mapping PIs and xmlns declarations before loading.","Use fully qualified clr-namespace with assembly= clause.","Test generated XAML against the real parser in CI."],"tags":["wpf","xaml","parsing","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"}