{"record":{"id":"158151104887f1c3","repo":"dotnet/wpf","slug":"sr-invalidcharintypename","errorCode":null,"errorMessage":"SR.InvalidCharInTypeName","messagePattern":"SR\\.InvalidCharInTypeName","errorType":"exception","errorClass":"TypeNameParserException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs","lineNumber":252,"sourceCode":"\n        // Subscript        ::= ‘[’ ‘,’* ‘]’\n        //\n        private void P_RepeatingSubscript()\n        {\n            // caller checks this.\n            Debug.Assert(_scanner.Token == GenericTypeNameScannerToken.SUBSCRIPT);\n\n            do\n            {\n                Callout_Subscript(_scanner.MultiCharTokenText);\n                _scanner.Read();\n            }\n            while (_scanner.Token == GenericTypeNameScannerToken.SUBSCRIPT);\n        }\n\n        private void ThrowOnBadInput()\n        {\n            throw new TypeNameParserException(SR.Format(SR.InvalidCharInTypeName, _scanner.ErrorCurrentChar, _inputText));\n        }\n\n        private void StartStack()\n        {\n            _stack = new Stack<TypeNameFrame>();\n            TypeNameFrame frame;\n            frame = new TypeNameFrame();\n            _stack.Push(frame);\n        }\n\n        private void Callout_FoundName(string prefix, string name)\n        {\n            TypeNameFrame frame = new TypeNameFrame\n            {\n                Name = name\n            };\n            string ns = _prefixResolver(prefix);\n            frame.Namespace = ns ?? throw new TypeNameParserException(SR.Format(SR.PrefixNotFound, prefix));","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs#L234-L270","documentation":"GenericTypeNameParser.ThrowOnBadInput throws TypeNameParserException (SR.InvalidCharInTypeName) when the scanner encounters a character that cannot appear in a generic type name, reporting the offending character and the full input text. It is the error exit of the parser loop reached from ParseName, ParseList, P_XamlTypeName, P_SimpleTypeName, and P_TypeParameters.","triggerScenarios":"Parsing a type name string (e.g. from x:Type markup extension or XamlType resolution) containing an invalid character — stray punctuation, unclosed brackets, spaces in wrong positions, or truncated generic syntax.","commonSituations":"Hand-written type name strings in XAML x:Type references; dynamically built type names with malformed generic arity syntax (e.g. \"List(Of T\" ); typos in assembly-qualified type references.","solutions":["Fix the type name string so it is syntactically valid (balanced brackets, valid identifier characters)","Validate/normalize the type string before passing it to XAML type resolution","Use Type.GetType or the fully qualified type reference instead of hand-built names"],"exampleFix":"// before\nvar type = new XamlTypeName(\"ns\", \"List[Int32\"); // unclosed subscript\n// after\nvar type = new XamlTypeName(\"ns\", \"List[Int32]\");","handlingStrategy":"try-catch","validationCode":"// validate the type name string before parsing\nif (string.IsNullOrWhiteSpace(typeName) || typeName.Count(c => c == '[') != typeName.Count(c => c == ']'))\n    throw new FormatException($\"Malformed type name: {typeName}\");","typeGuard":"static bool LooksLikeTypeName(string s) => !string.IsNullOrWhiteSpace(s) && s.Count(c => c=='[') == s.Count(c => c==']');","tryCatchPattern":"try { var name = ParseGenericTypeName(input); }\ncatch (TypeNameParserException ex) { /* invalid char in type name: ex.Message includes char and input */ }","preventionTips":["Ensure brackets/subscripts in generic type names are balanced","Escape or avoid invalid characters in type reference strings","Prefer fully qualified type names over hand-built ones"],"tags":["wpf","system-xaml","type-parsing","xaml-parser","typenameparserexception"],"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"}