{"record":{"id":"d9d33db56fa48182","repo":"dotnet/wpf","slug":"invalidoperationexception-sr-format-sr","errorCode":null,"errorMessage":"InvalidOperationException(SR.Format(SR.XamlTypeNameCannotGetPrefix, Namespace))","messagePattern":"InvalidOperationException\\(SR\\.Format\\(SR\\.XamlTypeNameCannotGetPrefix, Namespace\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs","lineNumber":225,"sourceCode":"            }\n\n            if (string.IsNullOrEmpty(Name))\n            {\n                throw new InvalidOperationException(SR.XamlTypeNameNameIsNullOrEmpty);\n            }\n\n            if (prefixGenerator is null)\n            {\n                result.Append('{');\n                result.Append(Namespace);\n                result.Append('}');\n            }\n            else\n            {\n                string prefix = prefixGenerator.Invoke(Namespace);\n                if (prefix is null)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.XamlTypeNameCannotGetPrefix, Namespace));\n                }\n\n                if (prefix.Length != 0)\n                {\n                    result.Append(prefix);\n                    result.Append(':');\n                }\n            }\n\n            if (HasTypeArgs)\n            {\n                // The subscript goes after the type args\n                ReadOnlySpan<char> name = GenericTypeNameScanner.StripSubscript(Name, out ReadOnlySpan<char> subscript);\n                result.Append(name);\n\n                result.Append('(');\n                ConvertListToStringInternal(result, TypeArguments, prefixGenerator);\n                result.Append(')');","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs#L207-L243","documentation":"When converting a XamlTypeName to its '{prefix:Name}' form, the prefixGenerator (typically the namespace resolver's prefix lookup) returned null for the type's namespace, meaning no XML prefix is mapped to that namespace URI. The library throws because it cannot serialize the name without a prefix.","triggerScenarios":"Calling XamlTypeName.ToString(...) with an IXamlNamespaceResolver that has no prefix registered for the type's Namespace URI; using a namespace-scoped resolver that does not cover the namespace in question.","commonSituations":"Namespace URI changed or typo'd so it no longer matches a registered xmlns; converting types from a namespace that was never declared in the resolver; serialization scope (NamespaceDeclaration context) where the prefix was only valid in a child scope.","solutions":["Register a prefix for the namespace URI in the resolver/prefix lookup before converting.","Use the '{namespaceUri}Name' form via the resolver-free ToString overload that emits the full namespace.","Verify the Namespace string exactly matches a declared xmlns URI (case and trailing slash sensitive)."],"exampleFix":"// before\nvar s = XamlTypeName.ToString(list, resolverWithoutPrefix); // InvalidOperationException\n// after\nnsResolver.AddNamespace(\"ex\", \"http://schemas.example.com/ns\"); // ensure mapping exists\nvar s = XamlTypeName.ToString(list, nsResolver);","handlingStrategy":"validation","validationCode":"if (prefixGenerator?.Invoke(xamlTypeName.Namespace) is null)\n    throw new InvalidOperationException($\"No prefix registered for namespace {xamlTypeName.Namespace}\");","typeGuard":"bool HasPrefixFor(XamlTypeName t, Func<string,string> prefixGen) =>\n    t?.Namespace is not null && prefixGen?.Invoke(t.Namespace) is not null;","tryCatchPattern":"try { var s = XamlTypeName.ToString(list, nsResolver); }\ncatch (InvalidOperationException ex) { /* register missing prefix or use '{uri}Name' form */ }","preventionTips":["Register all namespaces you will serialize with the resolver before conversion.","Compare namespace URIs exactly (case, trailing slash) with declared xmlns values.","Prefer the '{namespaceUri}Name' output form when no prefix mapping is guaranteed."],"tags":["xaml","namespace","serialization"],"backgroundTag":"missing-required-config","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"}