{"record":{"id":"547a53e191d8b43b","repo":"dotnet/wpf","slug":"sr-invalidtypestring","errorCode":null,"errorMessage":"SR.InvalidTypeString","messagePattern":"SR\\.InvalidTypeString","errorType":"exception","errorClass":"TypeNameParserException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs","lineNumber":298,"sourceCode":"            if (frame.TypeArgs is null)\n            {\n                frame.AllocateTypeArgs();\n            }\n\n            frame.TypeArgs.Add(typeName);\n        }\n\n        private void Callout_Subscript(string subscript)\n        {\n            TypeNameFrame frame = _stack.Peek();\n            frame.Name += subscript;\n        }\n\n        private XamlTypeName CollectNameFromStack()\n        {\n            if (_stack.Count != 1)\n            {\n                throw new TypeNameParserException(SR.Format(SR.InvalidTypeString, _inputText));\n            }\n\n            TypeNameFrame frame = _stack.Peek();\n            if (frame.TypeArgs.Count != 1)\n            {\n                throw new TypeNameParserException(SR.Format(SR.InvalidTypeString, _inputText));\n            }\n\n            XamlTypeName xamlTypeName = frame.TypeArgs[0];\n            return xamlTypeName;\n        }\n\n        private IList<XamlTypeName> CollectNameListFromStack()\n        {\n            if (_stack.Count != 1)\n            {\n                throw new TypeNameParserException(SR.Format(SR.InvalidTypeString, _inputText));\n            }","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs#L280-L316","documentation":"CollectNameFromStack validates that the parsed type name left exactly one frame on the parser stack. If input like 'ns:Type' parsed into multiple (or zero) frames — e.g. unbalanced parentheses or trailing tokens — the structure is not a single valid type name, so InvalidTypeString is thrown with the raw input text.","triggerScenarios":"XamlTypeName.Parse called with syntactically broken input: unbalanced generic braces 'ns:T1,ns:T2)', stray commas, or multiple comma-separated type names where a single type was expected.","commonSituations":"Hand-writing markup-extension arguments, storing type names in config strings, generically constructing type names in code with wrong join characters.","solutions":["Verify the type string is a single well-formed name like 'prefix:TypeName' or '(prefix:T1,prefix:T2)'","Check for unbalanced parentheses or stray commas in the string","Fix code that joins multiple type names when only one is accepted"],"exampleFix":"// before\nvar t = XamlTypeName.Parse(\"{ns:Foo,ns:Bar}\", resolver, out err);\n// after\nvar t = XamlTypeName.Parse(\"ns:Foo\", resolver, out err);","handlingStrategy":"validation","validationCode":"bool IsSingleTypeName(string s) =>\n    !string.IsNullOrWhiteSpace(s) && s.Count(c => c == '(') == s.Count(c => c == ')') && !s.Trim().EndsWith(\",\");","typeGuard":null,"tryCatchPattern":"try { var t = XamlTypeName.Parse(input, resolver, out var err); }\ncatch (TypeNameParserException) { /* log input text; fix syntax */ }","preventionTips":["Use ParseList for comma-separated inputs","Trim and sanity-check strings before parsing","Never concatenate type-name fragments blindly"],"tags":["xaml","type-parsing","syntax-error"],"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-22T01:17:13.364Z"}