{"record":{"id":"27d582886686ccca","repo":"dotnet/wpf","slug":"sr-collectionnumberofelementsmustbegreaterthanzero-27d582","errorCode":null,"errorMessage":"SR.CollectionNumberOfElementsMustBeGreaterThanZero","messagePattern":"SR\\.CollectionNumberOfElementsMustBeGreaterThanZero","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphTypeface.cs","lineNumber":228,"sourceCode":"\n        /// <summary>\n        /// Returns the binary image of font subset.\n        /// </summary>\n        /// <param name=\"glyphs\">Collection of glyph indices to be included into the subset.</param>\n        /// <returns>Binary image of font subset.</returns>\n        /// <remarks>\n        ///     Callers must have UnmanagedCode permission to call this API.\n        ///     Callers must have FileIOPermission or WebPermission to font location to call this API.\n        /// </remarks>\n        [CLSCompliant(false)]\n        public byte[] ComputeSubset(ICollection<ushort> glyphs)\n        {\n            CheckInitialized(); // This can only be called on fully initialized GlyphTypeface\n\n            ArgumentNullException.ThrowIfNull(glyphs);\n\n            if (glyphs.Count <= 0)\n                throw new ArgumentException(SR.CollectionNumberOfElementsMustBeGreaterThanZero, nameof(glyphs));\n\n            if (glyphs.Count > ushort.MaxValue)\n                throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsMustBeLessOrEqualTo, ushort.MaxValue), nameof(glyphs));\n\n            UnmanagedMemoryStream pinnedFontSource = FontSource.GetUnmanagedStream();\n\n            try\n            {\n                TrueTypeFontDriver trueTypeDriver = new TrueTypeFontDriver(pinnedFontSource, _originalUri);\n                trueTypeDriver.SetFace(FaceIndex);\n\n                return trueTypeDriver.ComputeFontSubset(glyphs);\n            }\n            catch (SEHException e)\n            {\n                throw Util.ConvertInPageException(FontSource, e);\n            }\n            finally","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphTypeface.cs#L210-L246","documentation":"GlyphTypeface.ComputeSubset throws ArgumentException with SR.CollectionNumberOfElementsMustBeGreaterThanZero when the glyphs collection is empty. ComputeSubset produces a subsetted font binary for a supplied list of glyph indices; an empty list yields a meaningless (or invalid) font file, so it is rejected up front.","triggerScenarios":"Calling ComputeSubset(Stream, ICollection<ushort>) with a glyphs collection that has Count == 0, typically because the set of glyphs used by the text was computed to be empty (no text, or all characters mapped to no glyphs).","commonSituations":"Subsetting fonts for download/embedding scenarios where the input text is an empty string; a bug upstream that skips glyph collection; passing a filtered glyph list that removed everything (e.g. filtering out glyphs < 0xFFFF).","solutions":["Check glyphs.Count > 0 before calling ComputeSubset and skip subsetting entirely when empty","Populate the collection with actual glyph indices via GlyphTypeface.CharacterToGlyphMap before subsetting","If subsetting for empty text, short-circuit and reuse or omit the font resource"],"exampleFix":"// before\nglyphTypeface.ComputeSubset(outStream, new ushort[0]);\n// after\nif (glyphs.Count > 0)\n    glyphTypeface.ComputeSubset(outStream, glyphs);\nelse\n    /* skip subsetting or copy full font */;","handlingStrategy":"validation","validationCode":"if (glyphs == null || glyphs.Count == 0)\n    return; // nothing to subset\n\nglyphTypeface.ComputeSubset(outStream, glyphs);","typeGuard":null,"tryCatchPattern":"try { glyphTypeface.ComputeSubset(outStream, glyphs); }\ncatch (ArgumentException ex) when (ex.ParamName == \"glyphs\")\n{\n    log.Warn(\"Subset skipped: empty glyph collection\", ex);\n}","preventionTips":["Early-return on empty input text instead of calling ComputeSubset","Derive glyph lists from CharacterToGlyphMap for distinct characters only","Add unit tests covering empty text -> no subset path"],"tags":["wpf","fonts","argument-exception","empty-collection","font-subsetting"],"backgroundTag":"empty-required-field","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"}