{"record":{"id":"2f69a9c4dc0902e0","repo":"dotnet/wpf","slug":"sr-invalidloccommentvalue","errorCode":null,"errorMessage":"SR.InvalidLocCommentValue","messagePattern":"SR\\.InvalidLocCommentValue","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizationComments.cs","lineNumber":144,"sourceCode":"                            escaped = false;\n                        }\n                    }\n                }\n                else\n                {\n                    // parsing the \"Value\" part\n                    if (tokenBuffer.Length == 0)\n                    {\n                        if (input[i] == CommentStart && !escaped)\n                        {\n                            // comment must begin with unescaped CommentStart\n                            tokenBuffer.Append(input[i]);\n                            escaped = false;\n                        }\n                        else if (!Char.IsWhiteSpace(input[i]))\n                        {\n                            // else, only white space is allows before an unescaped comment start char\n                            throw new FormatException(SR.Format(SR.InvalidLocCommentValue, currentPair.PropertyName, input));\n                        }\n                    }\n                    else\n                    {\n                        // inside the comment\n                        if (input[i] == CommentEnd)\n                        {\n                            if (!escaped)\n                            {\n                                // terminated by unescaped Comment\n                                currentPair.Value = tokenBuffer.ToString(1, tokenBuffer.Length - 1);\n                                tokens.Add(currentPair);\n                                tokenBuffer.Clear();\n                                currentPair = new PropertyComment();\n                            }\n                            else\n                            {\n                                // continue on escaped end char","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizationComments.cs#L126-L162","documentation":"LocalizationComments.ParsePropertyComments parses Localization.Comment attribute strings of the form 'PropertyName(Comment text)'. This FormatException is thrown when, outside a comment and not inside a property-name token, a non-whitespace character appears that is not an unescaped comment start '(' — i.e. the value text is malformed before any comment begins.","triggerScenarios":"Calling ParsePropertyComments (via the pairs iterator over Localization.Comments) with input where stray characters precede the '(' comment start, e.g. 'Text Some comment' instead of 'Text(Some comment)', or an unescaped ')' terminating a comment followed by junk.","commonSituations":"Hand-edited [Localization.Comments] attributes in .baml/XAML projects, values copied from documentation with the parentheses stripped or with extra prose before the '(', and localization resource files edited by non-IDE tools.","solutions":["Wrap every comment value in parentheses: Property(Comment).","Escape literal '(' or ')' inside comments with a backslash: '\\('.","Remove any non-whitespace characters between the property name and the opening parenthesis.","Escape a literal backslash as '\\\\' so it is not treated as an escape character."],"exampleFix":"// before\n[Localization.Comments]\nText This is the header comment\n// after\n[Localization.Comments]\nText(This is the header comment)","handlingStrategy":"validation","validationCode":"static bool IsValidLocCommentValue(string v)\n{\n    if (string.IsNullOrEmpty(v)) return false;\n    int i = 0;\n    while (i < v.Length)\n    {\n        char c = v[i];\n        if (c == '\\\\') { i += 2; continue; }\n        if (c == '(')\n        {\n            i++;\n            while (i < v.Length && v[i] != ')')\n            {\n                if (v[i] == '\\\\') i++;\n                else if (v[i] == '(') return false;\n                i++;\n            }\n            if (i >= v.Length) return false;\n        }\n        else if (!char.IsWhiteSpace(c) && i > 0 && v[i-1] == ' ') return false;\n        i++;\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { ParsePropertyComments(input); } catch (FormatException ex) { log.Warn($\"Malformed Localization.Comments value '{input}': {ex.Message}\"); }","preventionTips":["Always write Localization.Comments entries as Property(Comment).","Escape ( ) and \\ inside comment text.","Validate resource dictionaries after localization tooling edits."],"tags":["wpf","localization","format-exception","attribute-parsing"],"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"}