dotnet/wpf · error · ArgumentNullException

Value cannot be null. (Parameter 'writerVersion')

Error message

Value cannot be null. (Parameter 'writerVersion')

What it means

ArgumentNullException from the FormatVersion constructor when writerVersion is null. The writer version (a VersionPair of major/minor) is mandatory because the format block must record which version wrote the data; null would make the version block invalid.

Solutions

  1. Provide a valid VersionPair, e.g. new VersionPair(1, 0), for writerVersion
  2. Initialize the writerVersion variable before calling the constructor
  3. Default to the library's current versions (writer/reader/updater 1.0) when unsure

Example fix

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

Strategy: validation

Validate before calling

if (writerVersion == null) throw new ArgumentException("writerVersion 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, null, readerVersion, updaterVersion) — passing an uninitialized writer VersionPair.

Common situations: Building DataSpace version blocks in custom packaging code where the writer version was not initialized; refactoring code that dropped the writer version argument.

Related errors


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

Appendix: source

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

        }

        /// <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)