{"record":{"id":"32e8c0f447afa757","repo":"dotnet/wpf","slug":"error","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlContext.cs","lineNumber":318,"sourceCode":"                    _resolvePrefixCachedDelegate = new Func<string, string>(FindNamespaceByPrefix);\n                }\n\n                return _resolvePrefixCachedDelegate;\n            }\n        }\n\n        private string ResolveXamlNameNS(XamlName name)\n        {\n            return name.Namespace ?? FindNamespaceByPrefix(name.Prefix);\n        }\n\n        internal XamlType ResolveXamlType(string qName, bool skipVisibilityCheck)\n        {\n            string error;\n            XamlTypeName typeName = XamlTypeName.ParseInternal(qName, ResolvePrefixCachedDelegate, out error);\n            if (typeName is null)\n            {\n                throw new XamlParseException(error);\n            }\n\n            return GetXamlType(typeName, false, skipVisibilityCheck);\n        }\n\n        internal XamlMember ResolveDirectiveProperty(string xamlNS, string name)\n        {\n            if (xamlNS is not null)\n            {\n                return SchemaContext.GetXamlDirective(xamlNS, name);\n            }\n\n            return null;\n        }\n\n        // Only pass rootObjectType if the member is being looked up on the root object\n        internal virtual bool IsVisible(XamlMember member, XamlType rootObjectType)\n        {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlContext.cs#L300-L336","documentation":"XamlParseException thrown from ResolveXamlType when XamlTypeName.ParseInternal fails to parse the qualified name string into a XamlTypeName. The library throws it because the qName string is not a syntactically valid XAML type name (e.g. missing namespace prefix or malformed syntax), and the parse error message is carried into the exception.","triggerScenarios":"Calling ResolveXamlType (directly or via XamlType resolution from a XAML reader) with a qName string that fails XamlTypeName.ParseInternal — for example an empty string, a bare local name with no prefix where a prefix is required, unbalanced parentheses in markup-extension style names, or an unknown/empty prefix when no default namespace applies.","commonSituations":"Hand-built XAML node streams feeding a XamlXmlWriter/XamlObjectWriter with mistyped x:Type strings; programmatically resolving type names where a namespace prefix was never registered via a namespace declaration; refactored XML where the xmlns declaration was removed but element type names still reference the prefix.","solutions":["Fix the qualified name string to include a valid prefix declared in the current namespace context, e.g. 'sys:String' with xmlns:sys declared","Register the needed XmlnsDictionary/prefix mapping before resolving so the prefix parses and resolves","Wrap type-name resolution in try/catch on XamlParseException and inspect the parse error message","Validate the name with XamlTypeName.Parse on a test parser before passing it to the resolver"],"exampleFix":"// before\nvar type = context.ResolveXamlType(\"String\"); // no prefix declared -> parse fails\n// after\nvar type = context.ResolveXamlType(\"sys:String\"); // with xmlns:sys=\"clr-namespace:System;assembly=mscorlib\" declared","handlingStrategy":"try-catch","validationCode":"// validate before resolving\nif (string.IsNullOrWhiteSpace(qName) || (!qName.Contains(':') && prefixRequired))\n    throw new ArgumentException(\"Qualified XAML type name must include a declared prefix, e.g. 'sys:String'\");","typeGuard":null,"tryCatchPattern":"try { var type = context.ResolveXamlType(qName, false); }\ncatch (XamlParseException ex) { log.Error(\"Invalid XAML type name '{0}': {1}\", qName, ex.Message); }","preventionTips":["Always declare xmlns prefixes before referencing prefixed type names","Validate type-name strings with a parser before resolution","Keep namespace declarations in sync when refactoring XAML","Test type resolution with the exact qName strings used at runtime"],"tags":["xaml","parse-error","type-resolution"],"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"}