dotnet/wpf · error · ArgumentNullException

Value cannot be null. (Parameter 'readerVersion')

Error message

Value cannot be null. (Parameter 'readerVersion')

What it means

ArgumentNullException from the FormatVersion constructor when readerVersion is null. The reader version records the minimum version able to read the feature's data and is required for the DataSpace version block to be well-formed.

Solutions

  1. Pass a valid VersionPair for readerVersion (e.g. new VersionPair(1, 0))
  2. Ensure all three VersionPair arguments are initialized before construction
  3. Add null checks on parsed values before wrapping them in FormatVersion

Example fix

// before
var fv = new FormatVersion(id, writer, null, updater);
// after
var reader = new VersionPair(1, 0);
var fv = new FormatVersion(id, writer, reader, updater);
Defensive patterns

Strategy: validation

Validate before calling

if (readerVersion == null) throw new ArgumentException("readerVersion is required");
var fv = new FormatVersion(featureId, writerVersion, readerVersion, updaterVersion);

Type guard

static bool IsValidVersion(VersionPair v) => v != null;

Prevention

When it happens

Trigger: new FormatVersion(featureId, writerVersion, null, updaterVersion) — passing a null reader VersionPair.

Common situations: Custom transform/version-block construction where the reader version was omitted; copying constructor calls and missing one of the three version arguments.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/FormatVersion.cs:71

        /// <summary>
        /// Constructor for FormatVersion with given featureId and reader, updater,
        /// and writer version
        /// </summary>
        /// <param name="featureId">feature identifier</param>
        /// <param name="writerVersion">Writer Version</param>
        /// <param name="readerVersion">Reader Version</param>
        /// <param name="updaterVersion">Updater Version</param>
        public FormatVersion(String featureId,
                                VersionPair writerVersion,
                                VersionPair readerVersion,
                                VersionPair updaterVersion)
        {
            if (featureId == null)
                throw new ArgumentNullException(nameof(featureId));
            if (writerVersion == null)
                throw new ArgumentNullException(nameof(writerVersion));
            if (readerVersion == null)
                throw new ArgumentNullException(nameof(readerVersion));
            if (updaterVersion == null)
                throw new ArgumentNullException(nameof(updaterVersion));

            if (featureId.Length == 0)
            {
                throw new ArgumentException(SR.ZeroLengthFeatureID);
            }

            _featureIdentifier = featureId;
            _reader = readerVersion;
            _updater = updaterVersion;
            _writer = writerVersion;
        }

        #endregion Constructors

        //------------------------------------------------------
        //

View on GitHub (pinned to 81131a70a4)