{"record":{"id":"a6c6eddda988db7d","repo":"dotnet/wpf","slug":"sr-compositefontinvalidunicoderange","errorCode":null,"errorMessage":"SR.CompositeFontInvalidUnicodeRange","messagePattern":"SR\\.CompositeFontInvalidUnicodeRange","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FamilyMap.cs","lineNumber":221,"sourceCode":"                return true;\n            }\n\n            if (culture != null)\n            {\n                return familyMapLanguage.RangeIncludes(culture);\n            }   \n\n            return false;\n        }\n\n        internal Range[] Ranges\n        {\n            get { return _ranges; }\n        }\n\n        private static void ThrowInvalidUnicodeRange()\n        {\n            throw new FormatException(SR.CompositeFontInvalidUnicodeRange);\n        }\n\n        private static Range[] ParseUnicodeRanges(string unicodeRanges)\n        {\n            List<Range> ranges = new List<Range>(3);\n            int index = 0;\n            while (index < unicodeRanges.Length)\n            {\n                int firstNum;\n                if (!ParseHexNumber(unicodeRanges, ref index, out firstNum))\n                {\n                    ThrowInvalidUnicodeRange();\n                }\n\n                int lastNum = firstNum;\n\n                if (index < unicodeRanges.Length)\n                {","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FamilyMap.cs#L203-L239","documentation":"When a composite font (CompiledFontFamily/FontFamily XAML) specifies a FamilyMap whose UnicodeRanges attribute cannot be parsed, FamilyMap.ParseUnicodeRanges calls ThrowInvalidUnicodeRange, raising FormatException with CompositeFontInvalidUnicodeRange. Each range must be of the form U+XXXX or U+XXXX-U+YYYY, comma/whitespace separated, with valid hex values.","triggerScenarios":"Parsing a CompositeFont that contains a malformed unicodeRanges value: bad hex digits, reversed bounds (start > end), values above U+10FFFF, missing U+ prefix, or an empty range token.","commonSituations":"Hand-edited or third-party CompositeFont.xaml files, font fallback configurations copied with typos, or generated configs where hex values were formatted incorrectly.","solutions":["Fix the UnicodeRanges string in the composite font so every token matches U+XXXX[-U+XXXX] with valid hex and start <= end.","Validate range strings before loading, e.g. with Regex ^U\\+[0-9A-Fa-f]{1,6}(-U\\+[0-9A-Fa-f]{1,6})?$ and numeric comparison.","Load composite fonts from trusted, versioned resource files rather than user-supplied strings without validation."],"exampleFix":"<!-- before -->\n<FamilyMap Unicode=\"U+0600-U+05FF\"/>\n<!-- after -->\n<FamilyMap Unicode=\"U+0590-U+05FF\"/>","handlingStrategy":"validation","validationCode":"static readonly Regex RangeRx = new Regex(@\"^U\\+[0-9A-Fa-f]{1,6}(-U\\+[0-9A-Fa-f]{1,6})?$\");\nbool valid = unicodeRanges.Split(new[]{' ', ','}, StringSplitOptions.RemoveEmptyEntries).All(t => RangeRx.IsMatch(t));","typeGuard":null,"tryCatchPattern":"try { ParseCompositeFont(xml); }\ncatch (FormatException ex) { log.LogError($\"Invalid unicode range: {ex.Message}\"); }","preventionTips":["Validate CompositeFont XML against its schema before loading","Keep composite fonts in version-controlled resources, not hand-edited copies","Ensure range start <= end and values <= U+10FFFF"],"tags":["wpf","fonts","parsing","format"],"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-22T01:17:13.364Z"}