{"record":{"id":"570e7024396eff50","repo":"dotnet/wpf","slug":"invalidoperationexception-sr-xamltypenamenamespaceisnull","errorCode":null,"errorMessage":"InvalidOperationException(SR.XamlTypeNameNamespaceIsNull)","messagePattern":"InvalidOperationException\\(SR\\.XamlTypeNameNamespaceIsNull\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs","lineNumber":206,"sourceCode":"        internal static IList<XamlTypeName> ParseListInternal(string typeNameList, Func<string, string> prefixResolver, out string error)\n        {\n            GenericTypeNameParser nameParser = new GenericTypeNameParser(prefixResolver);\n            IList<XamlTypeName> xamlTypeName = nameParser.ParseList(typeNameList, out error);\n            return xamlTypeName;\n        }\n\n        internal string ConvertToStringInternal(Func<string, string> prefixGenerator)\n        {\n            StringBuilder result = new StringBuilder();\n            ConvertToStringInternal(result, prefixGenerator);\n            return result.ToString();\n        }\n\n        internal void ConvertToStringInternal(StringBuilder result, Func<string, string> prefixGenerator)\n        {\n            if (Namespace is null)\n            {\n                throw new InvalidOperationException(SR.XamlTypeNameNamespaceIsNull);\n            }\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                {","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlTypeName.cs#L188-L224","documentation":"ConvertToStringInternal cannot render a XamlTypeName to string form because its Namespace property is null. A XamlTypeName only round-trips to '{ns}Name' syntax when it carries a namespace; this library treats a namespace-less name as an invalid state rather than emitting a wrong string.","triggerScenarios":"Calling ToString()/ToString(IList<XamlTypeName>, IXamlNamespaceResolver) on a XamlTypeName constructed without a namespace (e.g. new XamlTypeName(null, \"Foo\") or a default-initialized instance).","commonSituations":"Manually constructing XamlTypeName instances and forgetting the namespace argument; deserializing/parsing failures that left a partially populated instance; copying Name but not Namespace between instances.","solutions":["Set a valid Namespace on the XamlTypeName before calling ToString.","Construct the instance with both namespace and name, e.g. new XamlTypeName(ns, name).","If the namespace is only known as a prefix, resolve the prefix to the full namespace URI first."],"exampleFix":"// before\nvar t = new XamlTypeName(null, \"MyType\");\nvar s = t.ToString(); // InvalidOperationException\n// after\nvar t = new XamlTypeName(\"http://schemas.example.com/ns\", \"MyType\");\nvar s = t.ToString(); // '{http://schemas.example.com/ns}MyType'","handlingStrategy":"type-guard","validationCode":"if (xamlTypeName is null || xamlTypeName.Namespace is null)\n    throw new InvalidOperationException(\"XamlTypeName must have a Namespace before ToString.\");","typeGuard":"bool CanConvertToString(XamlTypeName t) => t is not null && t.Namespace is not null && !string.IsNullOrEmpty(t.Name);","tryCatchPattern":"try { var s = xamlTypeName.ToString(); }\ncatch (InvalidOperationException) { /* reconstruct with namespace or skip */ }","preventionTips":["Always construct XamlTypeName with both namespace and name arguments.","Never leave Name/Namespace fields default-initialized in longer-lived objects.","Check Namespace/Name before serialization loops."],"tags":["xaml","invalid-state"],"backgroundTag":"missing-required-argument","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"}