{"record":{"id":"2c4b92b44e88cca0","repo":"unoplatform/uno","slug":"could-not-lookup-prefix-for-namespace-0","errorCode":null,"errorMessage":"Could not lookup prefix for namespace '{0}'","messagePattern":"Could not lookup prefix for namespace '(.+?)'","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs","lineNumber":251,"sourceCode":"\t\tpublic override string ToString ()\n\t\t{\n\t\t\treturn ToString (null);\n\t\t}\n\n\t\tpublic string ToString (INamespacePrefixLookup prefixLookup)\n\t\t{\n\t\t\tif (Namespace == null)\n\t\t\t\tthrow new InvalidOperationException (\"Namespace must be set before calling ToString method.\");\n\t\t\tif (Name == null)\n\t\t\t\tthrow new InvalidOperationException (\"Name must be set before calling ToString method.\");\n\n\t\t\tstring ret;\n\t\t\tif (prefixLookup == null)\n\t\t\t\tret = String.Concat (\"{\", Namespace, \"}\", Name);\n\t\t\telse {\n\t\t\t\tstring p = prefixLookup.LookupPrefix (Namespace);\n\t\t\t\tif (p == null)\n\t\t\t\t\tthrow new InvalidOperationException (String.Format (CultureInfo.InvariantCulture, \"Could not lookup prefix for namespace '{0}'\", Namespace));\n\t\t\t\tret = p.Length == 0 ? Name : p + \":\" + Name;\n\t\t\t}\n\t\t\tstring arr = null;\n\t\t\tif (ret [ret.Length - 1] == ']') {\n\t\t\t\tint idx = ret.LastIndexOf ('[');\n\t\t\t\tarr = ret.Substring (idx);\n\t\t\t\tret = ret.Substring (0, idx);\n\t\t\t}\n\n\t\t\tif (TypeArguments.Count > 0)\n\t\t\t\tret += String.Concat (\"(\", DoToString (TypeArguments, prefixLookup), \")\");\n\n\t\t\treturn ret + arr;\n\t\t}\n\t}\n}\n","sourceCodeStart":233,"sourceCodeEnd":268,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs#L233-L268","documentation":"Thrown by XamlTypeName.ToString(INamespacePrefixLookup) when a non-null prefixLookup is provided but LookupPrefix returns null for the XamlTypeName's namespace. The prefix-based serialization format requires a known prefix for every namespace; a missing mapping means the XAML prefix table is incomplete relative to the types being serialized.","triggerScenarios":"Calling ToString(prefixLookup) where prefixLookup is a PrefixLookup (or custom INamespacePrefixLookup) that was built from a different or smaller set of xmlns declarations than the XamlTypeName's Namespace expects.","commonSituations":"Serializing a type whose namespace was not declared in the source XAML document. Mixing XamlTypeName objects from one schema context with a prefix lookup from another. XAML namespace aliasing or remapping where the prefix table wasn't updated to match.","solutions":["Ensure every namespace used by your XamlTypeName objects has a corresponding xmlns prefix registered in the INamespacePrefixLookup before serialization.","Call ToString() without arguments (pass null for prefixLookup) to get the brace-format form ({ns}Name) which does not require prefix resolution.","Check prefixLookup.LookupPrefix(ns) before calling ToString and register the missing namespace if it returns null."],"exampleFix":"// before\nstring output = xamlTypeName.ToString(prefixLookup); // prefixLookup missing the namespace\n\n// after\nif (prefixLookup.LookupPrefix(xamlTypeName.Namespace) == null)\n    // register or fall back to brace format\n    output = xamlTypeName.ToString(); // {ns}Name\nelse\n    output = xamlTypeName.ToString(prefixLookup);","handlingStrategy":"validation","validationCode":"if (prefixLookup.LookupPrefix(tn.Namespace) == null)\n    return tn.ToString(); // brace format fallback\nreturn tn.ToString(prefixLookup);","typeGuard":"static bool HasPrefix(INamespacePrefixLookup lookup, string ns)\n    => lookup?.LookupPrefix(ns) != null;","tryCatchPattern":"try { return tn.ToString(prefixLookup); }\ncatch (InvalidOperationException) { return tn.ToString(); } // fallback to {ns}Name","preventionTips":["Ensure the prefix table is built from the same xmlns declarations as the types being serialized.","Fall back to brace-format ToString() (no prefix lookup) when prefix resolution may be incomplete."],"tags":["xaml","schema","namespace","prefix","serialization","uno-xaml"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}