{"record":{"id":"6eb2c5f3fa20e85b","repo":"dotnet/wpf","slug":"sr-collectionnumberofelementsmustbegreaterthanzero","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/GlyphRun.cs","lineNumber":433,"sourceCode":"                    throw new ArgumentException(SR.SidewaysRTLTextIsNotSupported);\n\n                // NOTE:  In previous versions this function would estimate the size\n                // of this glyph run's bitmaps and compare it against the theoretical\n                // maximum size allowed before rendering falls back to using geometry.\n                // This was done in order to produce a managed exception where we might\n                // hit overflow or memory allocation issues in native code.\n                // We no longer own the code the produces these bitmaps so we can't reliably\n                // avoid the issue here any longer.\n            }\n            else\n            {\n                ArgumentOutOfRangeException.ThrowIfEqual(renderingEmSize, double.NaN);\n                ArgumentOutOfRangeException.ThrowIfNegative(renderingEmSize);\n                ArgumentNullException.ThrowIfNull(glyphTypeface);\n                ArgumentNullException.ThrowIfNull(glyphIndices);\n\n                if (glyphIndices.Count <= 0)\n                    throw new ArgumentException(SR.CollectionNumberOfElementsMustBeGreaterThanZero, nameof(glyphIndices));\n\n                if (glyphIndices.Count > MaxGlyphCount)\n                {\n                    throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsMustBeLessOrEqualTo, MaxGlyphCount), nameof(glyphIndices));\n                }\n\n                ArgumentNullException.ThrowIfNull(advanceWidths);\n\n                if (advanceWidths.Count != glyphIndices.Count)\n                    throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsShouldBeEqualTo, glyphIndices.Count), nameof(advanceWidths));\n\n                if (glyphOffsets != null && glyphOffsets.Count != 0 && glyphOffsets.Count != glyphIndices.Count)\n                    throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsShouldBeEqualTo, glyphIndices.Count), nameof(glyphOffsets));\n\n                // We should've caught all invalid cases above and thrown appropriate exceptions.\n                Invariant.Assert(false);\n            }\n","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs#L415-L451","documentation":"GlyphRun.Initialize requires the glyphIndices collection to contain at least one glyph; an empty collection cannot represent a drawable run. It throws ArgumentException naming the glyphIndices parameter.","triggerScenarios":"Calling the GlyphRun constructor, TryCreate, or EndInit with an empty (Count == 0) glyphIndices list — e.g. shaping an empty string but still constructing a run.","commonSituations":"Shaping empty or whitespace-only text that yields zero glyphs; clearing a text buffer and unconditionally building a GlyphRun.","solutions":["Return early / skip GlyphRun creation when there are no glyphs","Pass null-safe handling: only construct the run if glyphIndices.Count > 0","Render an empty visual (e.g. empty DrawingContext) instead of an empty run"],"exampleFix":"// before\nvar run = new GlyphRun(tf, 0, false, 12, glyphs /* empty */, ...);\n// after\nif (glyphs.Count > 0) { var run = new GlyphRun(...); dc.DrawText(...); }","handlingStrategy":"validation","validationCode":"if (glyphIndices == null || glyphIndices.Count == 0)\n    return; // skip drawing instead of constructing a GlyphRun","typeGuard":"static bool HasGlyphs(ICollection<ushort> glyphs) => glyphs != null && glyphs.Count > 0;","tryCatchPattern":"try { var run = new GlyphRun(...); }\ncatch (ArgumentException ex) when (ex.ParamName == \"glyphIndices\") { /* skip empty run */ }","preventionTips":["Early-return when shaping yields zero glyphs","Never construct runs for empty strings","Render nothing (or a placeholder) for empty text"],"tags":["wpf","glyphrun","empty-collection","argument-validation"],"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-22T01:17:13.364Z"}