dotnet/wpf · error · ArgumentOutOfRangeException

SR.Effect_ShaderEffectPadding

Error message

SR.Effect_ShaderEffectPadding

What it means

The PaddingTop property setter of ShaderEffect rejects negative values with an ArgumentOutOfRangeException carrying Effect_ShaderEffectPadding. Padding expands the region the effect renders into and must be zero or positive.

Solutions

  1. Set PaddingTop to a non-negative value (0 or greater).
  2. Clamp before assigning: effect.PaddingTop = Math.Max(0, computedPadding);
  3. If shrinking is intended, note that padding cannot be negative; restructure the effect instead.

Example fix

// before
effect.PaddingTop = extraSpace; // extraSpace may be negative
// after
effect.PaddingTop = Math.Max(0, extraSpace);
Defensive patterns

Strategy: validation

Validate before calling

if (topPadding < 0) topPadding = 0;
effect.PaddingTop = topPadding;

Type guard

static double ClampPadding(double v) => Math.Max(0.0, v);

Prevention

When it happens

Trigger: Assigning PaddingTop = -n (or a computed value that goes negative) on a ShaderEffect-derived class instance.

Common situations: Computing padding from a formula that can yield negative results (e.g. subtracting sizes); binding a negative value; copy/paste errors swapping signs.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs:44

        }

        /// <summary>
        /// Padding is used to specify that an effect's output texture is larger than its input
        /// texture in a specific direction, e.g. for a drop shadow effect.
        /// </summary>
        protected double PaddingTop
        {
            get
            {
                ReadPreamble();
                return _topPadding;
            }
            set
            {
                WritePreamble();
                if (value < 0.0)
                {
                    throw new ArgumentOutOfRangeException(nameof(value), value, SR.Effect_ShaderEffectPadding);
                }
                else
                {
                    _topPadding = value;
                    RegisterForAsyncUpdateResource();
                }
                WritePostscript();
            }
        }

        /// <summary>
        /// Padding is used to specify that an effect's output texture is larger than its input
        /// texture in a specific direction, e.g. for a drop shadow effect.
        /// </summary>
        protected double PaddingBottom
        {
            get
            {

View on GitHub (pinned to 81131a70a4)