dotnet/wpf · error · ArgumentOutOfRangeException

CommitCountPolicy must be greater than zero.

Error message

CommitCountPolicy must be greater than zero.

What it means

The subsetter requires a positive commit count. Passing commitCount < 1 (zero or negative) throws ArgumentOutOfRangeException with ReachPackaging_CommitCountPolicyLessThan1. A count of 0 or less has no meaning for font subsetting batches.

Solutions

  1. Pass a commit count >= 1
  2. Clamp or validate the configured value before calling
  3. Fix the configuration source that yields a non-positive count

Example fix

// before
int count = int.Parse(config["SubsetCount"]); // could be 0
fontSubsetter.SetFontSubsettingCountPolicy(count);
// after
int count = Math.Max(1, int.Parse(config["SubsetCount"] ?? "1"));
fontSubsetter.SetFontSubsettingCountPolicy(count);
Defensive patterns

Strategy: validation

Validate before calling

if (count < 1) throw new ArgumentOutOfRangeException(nameof(count));
fontSubsetter.SetFontSubsettingCountPolicy(count);

Prevention

When it happens

Trigger: Calling SetFontSubsettingCountPolicy with 0 or a negative value, often from a misparsed configuration value or an uninitialized int defaulting through a decrement.

Common situations: Reading the subsetting count from app config where the value is 0/empty, or computing the count dynamically and getting a non-positive result.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/37aecbb736645a59. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/XpsFontSubsetter.cs:363

          _commitPolicy = policy;
        }

        /// <summary> 
        /// Determines the number of signals subsets will be commited on
        ///</summary> 
        public
        void
        SetSubsetCommitCountPolicy( int commitCount )
        {
            if( _commitPolicy == FontSubsetterCommitPolicies.CommitEntireSequence &&
                commitCount != 1 )
            {
                throw new ArgumentOutOfRangeException(SR.ReachPackaging_SequenceCntMustBe1);
            }
            else
            if( commitCount < 1 )
            {
                throw new ArgumentOutOfRangeException(SR.ReachPackaging_CommitCountPolicyLessThan1);
            }
            _commitCountPolicy = commitCount;
        }
        #endregion Public methods
        
        #region Private data

        private IDictionary<Uri, FEMCacheItem>  _fontEmbeddingManagerCache;
        private BasePackagingPolicy             _packagingPolicy;
        private FontSubsetterCommitPolicies     _commitPolicy = FontSubsetterCommitPolicies.CommitEntireSequence;
        private int                             _commitCountPolicy = 1;
        private int                             _currentCommitCnt = 0;
        #endregion Private data

        #region Private methods

        /// <summary>
        /// Acquires a cache item for the specified font.  If one

View on GitHub (pinned to 81131a70a4)