stride3d/stride · warning · ArgumentException

' ' is not a sRGB format

Error message

'{format}' is not a sRGB format

What it means

The HasNonSRgbEquivalent property accessor throws ArgumentException when the wrapped format is NOT an sRGB format, since a non-sRGB conversion target only exists for sRGB formats. The property is meant to be queried only when format.IsSRgb is true.

Solutions

  1. Check format.IsSRgb before querying; treat linear formats as already being the non-sRGB equivalent.
  2. Return the format itself when !IsSRgb instead of calling HasNonSRgbEquivalent.
  3. Filter formats to IsSRgb entries before processing.

Example fix

// before
var linear = helper.HasNonSRgbEquivalent ? helper.GetNonSRgbEquivalent() : helper.Format;
// after
var linear = helper.Format.IsSRgb
    ? (helper.HasNonSRgbEquivalent ? helper.GetNonSRgbEquivalent() : helper.Format)
    : helper.Format;
Defensive patterns

Strategy: type-guard

Validate before calling

if (format.IsSRgb)
{
    // safe to query
    var has = helper.HasNonSRgbEquivalent;
}

Type guard

bool CanQueryNonSRgbEquivalent(PixelFormat fmt) => fmt.IsSRgb;

Try / catch

try { return helper.HasNonSRgbEquivalent ? helper.GetNonSRgbEquivalent() : helper.Format; }
catch (ArgumentException) { return helper.Format; /* already linear */ }

Prevention

When it happens

Trigger: Evaluating helper.HasNonSRgbEquivalent on a PixelFormatExtensions instance whose format is a plain linear format (e.g. R8G8B8A8_UNorm), typically in code stripping sRGB suffixes without checking IsSRgb first.

Common situations: Asset pipelines downgrading textures from sRGB to linear that run over every format including already-linear ones; generic format-table code that assumes all inputs are sRGB; refactors that changed default formats from _SRgb to linear.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/f2fbba71de81f5c1. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Foundation/Graphics/PixelFormatExtensions.cs:288

        /// </exception>
        public bool HasSRgbEquivalent
            => format.IsSRgb
                ? throw new ArgumentException($"'{format}' is already an sRGB pixel format", nameof(format))
                : sRgbConversion.ContainsKey(format);

        /// <summary>
        ///   Gets a value indicating if the <see cref="PixelFormat"/> has an equivalent non-sRGB format.
        /// </summary>
        /// <returns>
        ///   <see langword="true"/> if the pixel format has an non-sRGB equivalent;
        ///   <see langword="false"/> otherwise.
        /// </returns>
        /// <exception cref="ArgumentException">
        ///   The provided pixel format is not an sRGB format.
        /// </exception>
        public bool HasNonSRgbEquivalent
            => !format.IsSRgb
                ? throw new ArgumentException($"'{format}' is not a sRGB format", nameof(format))
                : sRgbConversion.ContainsKey(format);

        /// <summary>
        ///   Gets the equivalent sRGB format to the <see cref="PixelFormat"/>.
        /// </summary>
        /// <returns>
        ///   The equivalent sRGB format if it exists, or the provided pixel format otherwise.
        /// </returns>
        public PixelFormat ToSRgb()
            => format.IsSRgb || !sRgbConversion.TryGetValue(format, out var srgbFormat)
                ? format
                : srgbFormat;

        /// <summary>
        ///   Gets the equivalent non-sRGB format to the provided <see cref="PixelFormat"/>.
        /// </summary>
        /// <returns>
        ///   The equivalent non-sRGB format if it exists, or the provided pixel format otherwise.

View on GitHub (pinned to 96fad776d2)