BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException

Font size must be higher than 0

Error message

Font size must be higher than 0

What it means

Thrown by FontGrabber.GetFont(string familyName, float size, FontStyle style) when size <= 0. A non-positive em-size is invalid for System.Drawing.Font, so the method rejects it before constructing anything. Family-name validity is handled separately (returns null for unknown families).

Source

Thrown at source/KlocTools/Subsystems/FontGrabber.cs:29

namespace Klocman.Subsystems
{
    public sealed class FontGrabber
    {
        private readonly Dictionary<string, FontFamily> _validFontFamilies = new();

        public FontGrabber()
        {
            UpdateFontFamilies();
        }

        public IEnumerable<FontFamily> ValidFontFamilies => _validFontFamilies.Values;
        public IEnumerable<string> ValidFontFamilyNames => _validFontFamilies.Keys;

        public Font GetFont(string familyName, float size, FontStyle style)
        {
            if (size <= 0)
                throw new ArgumentException("Font size must be higher than 0");

            return _validFontFamilies.ContainsKey(familyName)
                ? new Font(_validFontFamilies[familyName], size, style)
                : null;
        }

        public FontFamily GetFontFamily(string familyName)
        {
            return _validFontFamilies.ContainsKey(familyName) ? _validFontFamilies[familyName] : null;
            //throw new ArgumentException("Invalid font family name");
        }

        private void UpdateFontFamilies()
        {
            using (var installedFonts = new InstalledFontCollection())
            {
                foreach (var t in installedFonts.Families.Where(t => t.IsStyleAvailable(FontStyle.Regular)))
                {

View on GitHub (pinned to 608321de98)

Solutions

  1. Clamp the size to a positive minimum before calling: size = Math.Max(size, 1f);
  2. Treat 0/negative as 'use default' and substitute a sensible default size.
  3. Validate config-loaded font sizes at load time and reject non-positive values.

Example fix

// before
var font = grabber.GetFont(name, userSize, style); // userSize may be 0

// after
var font = grabber.GetFont(name, Math.Max(userSize, 8f), style);
Defensive patterns

Strategy: validation

Validate before calling

size = float.IsNaN(size) || size <= 0 ? 8f : size;
var font = grabber.GetFont(familyName, size, style);

Type guard

static bool IsValidFontSize(float size) => !float.IsNaN(size) && !float.IsInfinity(size) && size > 0f;

Prevention

When it happens

Trigger: Calling GetFont with size 0, a negative size, or NaN/-Infinity (float). Common when the size is read from config or computed (e.g. baseSize * factor where factor is 0).

Common situations: Configurable font sizes defaulting to 0 when unset, DPI-scaling math producing 0 for very small factors, division-by-zero producing NaN, or passing an unset int/float setting straight through.

Related errors


AI-assisted analysis of BCUninstaller/Bulk-Crap-Uninstaller@608321de98 (2026-08-13). Data as JSON: /api/errors/7e67f82fb93bf19e. Report an issue: GitHub.