{"record":{"id":"dc0955854a7cce7f","repo":"icsharpcode/ILSpy","slug":"expected-type-name","errorCode":null,"errorMessage":"Expected type name","messagePattern":"Expected type name","errorType":"exception","errorClass":"ReflectionNameParseException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/Documentation/IdStringProvider.cs","lineNumber":1083,"sourceCode":"\r\n\t\t/// <summary>\r\n\t\t/// Reads a type name segment (no special characters). If allowDots is true,\r\n\t\t/// dots are included in the segment (for the top-level name which includes namespace).\r\n\t\t/// </summary>\r\n\t\tstatic string ReadTypeNameSegment(string typeName, ref int pos, bool allowDots)\r\n\t\t{\r\n\t\t\tint start = pos;\r\n\t\t\twhile (pos < typeName.Length)\r\n\t\t\t{\r\n\t\t\t\tchar c = typeName[pos];\r\n\t\t\t\tif (IsIDStringSpecialCharacter(c))\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tif (!allowDots && c == '.')\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tpos++;\r\n\t\t\t}\r\n\t\t\tif (pos == start)\r\n\t\t\t\tthrow new ReflectionNameParseException(pos, \"Expected type name\");\r\n\t\t\treturn typeName.Substring(start, pos - start);\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Reads a type parameter count from the current position in an ID string.\r\n\t\t/// Handles both `n (unbound) and {T1,T2,...} (bound) syntax.\r\n\t\t/// For bound syntax, counts the arguments without fully parsing them\r\n\t\t/// (we only need the arity for type definition lookup).\r\n\t\t/// </summary>\r\n\t\tstatic int ReadTypeParameterCountFromIdString(string typeName, ref int pos)\r\n\t\t{\r\n\t\t\tif (pos >= typeName.Length)\r\n\t\t\t\treturn 0;\r\n\r\n\t\t\tif (typeName[pos] == '`')\r\n\t\t\t{\r\n\t\t\t\tpos++;\r\n\t\t\t\treturn ReflectionHelper.ReadTypeParameterCount(typeName, ref pos);\r","sourceCodeStart":1065,"sourceCodeEnd":1101,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/Documentation/IdStringProvider.cs#L1065-L1101","documentation":"ReflectionNameParseException thrown by ReadTypeNameSegment when it expects a type-name segment but finds a special character (or end of string) immediately at the current position (pos == start). It is reached indirectly through FindEntity -> ParseTypeNameParts whenever the type-name portion of an ID string is empty or starts with a separator/special character.","triggerScenarios":"ID strings whose type portion has an empty segment: \"T:.Foo\" (leading dot in the type part), \"T:Foo.\" (trailing dot producing an empty nested name), \"T:{System.Int32}.Bar\" (special '{' where a name is expected), or \"T:\" with nothing after.","commonSituations":"Hand-built or programmatically-constructed ID strings that drop a segment; crefs copied from external tooling that emit a leading/trailing dot or a brace where a name should be.","solutions":["Ensure every type-name segment between dots is non-empty and contains no ID-string special characters.","Strip stray leading/trailing dots from the type portion before resolving.","Use GetIdString on a real entity to produce a well-formed ID string rather than building one by hand."],"exampleFix":"// before\nvar e = IdStringProvider.FindEntity(\"T:.Foo.Bar\", context);\n\n// after\nvar e = IdStringProvider.FindEntity(\"T:Foo.Bar\", context);","handlingStrategy":"try-catch","validationCode":"static bool LooksLikeTypeIdString(string s)\n{\n    if (s == null || s.Length < 2 || s[1] != ':') return false;\n    string typePart = s.Substring(2);\n    if (typePart.Length == 0) return false;\n    var parts = typePart.Split('.');\n    return parts.All(p => p.Length > 0);\n}","typeGuard":null,"tryCatchPattern":"try { return IdStringProvider.FindEntity(idString, context); }\ncatch (ReflectionNameParseException ex) { logger.Warn($\"Malformed ID string at {ex.Position}: {ex.Message}\"); return null; }","preventionTips":["Do not hand-build ID strings; emit them via GetIdString.","Strip stray leading/trailing dots and braces from the type portion before resolving.","Catch ReflectionNameParseException whenever ID strings come from external sources."],"tags":["id-string","parse","reflection-name","type-name"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}