{"record":{"id":"f6f03042de1f202b","repo":"dotnet/wpf","slug":"sr-invalidloccommenttarget","errorCode":null,"errorMessage":"SR.InvalidLocCommentTarget","messagePattern":"SR\\.InvalidLocCommentTarget","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizationComments.cs","lineNumber":116,"sourceCode":"                        }\n\n                        // else ignore whitespace at the beginning of the PropertyName name\n                    }\n                    else\n                    {\n                        if (input[i] == CommentStart && !escaped)\n                        {\n                            if (i > 0)\n                            {\n                                // terminate the PropertyName by an unescaped CommentStart char\n                                currentPair.PropertyName = tokenBuffer.ToString();\n                                tokenBuffer.Clear();\n                                i--; // put back this char and continue\n                            }\n                            else\n                            {\n                                // can't begin with unescaped comment start char.\n                                throw new FormatException(SR.Format(SR.InvalidLocCommentTarget, input));\n                            }\n                        }\n                        else if (input[i] == EscapeChar && !escaped)\n                        {\n                            escaped = true;\n                        }\n                        else\n                        {\n                            tokenBuffer.Append(input[i]);\n                            escaped = false;\n                        }\n                    }\n                }\n                else\n                {\n                    // parsing the \"Value\" part\n                    if (tokenBuffer.Length == 0)\n                    {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizationComments.cs#L98-L134","documentation":"When parsing localization comments ( Loc comments in XAML), ParsePropertyComments throws this FormatException if a localization target token starts with an unescaped comment-start character. Target names in the comment must be valid identifiers or escaped; an unescaped start character makes the target unparseable.","triggerScenarios":"A Loc comment like [Loc]$[... where the target begins with the comment-start/escape character without escaping — e.g. malformed comment syntax [$...] written incorrectly, or target names containing special characters unescaped.","commonSituations":"Hand-written Loc comments with typos in the bracket syntax; localization targets whose names contain special characters (like '[') that were not escaped; tools generating comments with wrong escaping.","solutions":["Fix the Loc comment so the target is a valid identifier without a leading unescaped start char","Escape special characters in the target name with the escape character","Check the comment against the documented Loc comment syntax","Regenerate the comments with the localization tooling instead of hand-editing"],"exampleFix":"// before\n<!-- Loc $$foo --> (unescaped start char in target)\n// after\n<!-- Loc foo -->","handlingStrategy":"validation","validationCode":"// Validate Loc comment syntax before localization processing\nif (System.Text.RegularExpressions.Regex.IsMatch(comment, @\"\\$[^\\\\$]\")) throw new FormatException(\"Unescaped start char in Loc comment target\");","typeGuard":null,"tryCatchPattern":"try { comments = ParseLocComments(xamlComment); } catch (FormatException ex) { log.LogWarning($\"Skipping malformed Loc comment: {ex.Message}\"); }","preventionTips":["Follow the documented Loc comment syntax exactly","Escape special characters in localization target names","Generate Loc comments via tooling rather than hand-editing","Add CI validation of Loc comments in XAML resources"],"tags":["localization","comments","format","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"}