{"record":{"id":"7b710848ecf2d1f6","repo":"dotnet/wpf","slug":"sr-charactermetrics-toomanyfields","errorCode":null,"errorMessage":"SR.CharacterMetrics_TooManyFields","messagePattern":"SR\\.CharacterMetrics_TooManyFields","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CharacterMetrics.cs","lineNumber":180,"sourceCode":"                        out metrics[fieldIndex]\n                        ))\n                    {\n                        throw new ArgumentException(SR.Format(SR.CannotConvertStringToType, field.ToString(), \"double\"));\n                    }\n                }\n                else if (fieldIndex < NumRequiredFields)\n                {\n                    // Empty field; make sure it's an optional one.\n                    throw new ArgumentException(SR.CharacterMetrics_MissingRequiredField);\n                }\n\n                ++fieldIndex;\n\n                if (j < s.Length)\n                {\n                    // There's a comma so check if we've exceeded the number of fields.\n                    if (fieldIndex == NumFields)\n                        throw new ArgumentException(SR.CharacterMetrics_TooManyFields);\n\n                    // Initialize character index for next iteration.\n                    i = j + 1;\n                }\n                else\n                {\n                    // No more fields; check if we have all required fields.\n                    if (fieldIndex < NumRequiredFields)\n                    {\n                        throw new ArgumentException(SR.CharacterMetrics_MissingRequiredField);\n                    }\n\n                    break;\n                }\n            }\n\n            return metrics;\n        }","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/CharacterMetrics.cs#L162-L198","documentation":"CharacterMetrics.ParseMetrics parses a comma-separated metrics string (e.g. from a FontFamily 'DeviceFontName' style definition). The string may contain at most NumFields (= 8: LeftSideBearing, RightSideBearing, TopSideBearing, BottomSideBearing, Width, Height, BlackBoxWidth, BlackBoxHeight) comma-separated fields. This ArgumentException is thrown when the string has more fields than that.","triggerScenarios":"Calling the CharacterMetrics(string metricsString) constructor with a string containing 9 or more comma-separated values.","commonSituations":"Hand-edited or machine-generated font metrics strings that append trailing fields or accidentally include extra commas; pasting metrics from a different format with more columns.","solutions":["Remove extra comma-separated fields so the string has at most 8 values.","Trim trailing/stray commas from the metrics string before constructing CharacterMetrics.","Split the string on ',' and validate the count is between NumRequiredFields (4) and 8 before constructing."],"exampleFix":"// before\nnew CharacterMetrics(\"0.1,0.2,0.3,0.4,1.0,2.0,1.2,2.2,0.5\");\n// after\nnew CharacterMetrics(\"0.1,0.2,0.3,0.4,1.0,2.0,1.2,2.2\");","handlingStrategy":"validation","validationCode":"string[] fields = metricsString.Split(',');\nif (fields.Length > 8)\n    throw new FormatException($\"CharacterMetrics string must have at most 8 fields, got {fields.Length}.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Split and count fields before constructing CharacterMetrics.","Trim leading/trailing commas from generated metrics strings.","Keep metrics generators emitting exactly 8 columns."],"tags":["wpf","charactermetrics","parsing","argument-exception"],"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"}