dotnet/wpf · error · ArgumentNullException

Value cannot be null. (Parameter 'value')

Error message

Value cannot be null. (Parameter 'value')

What it means

ArgumentNullException from the FormatVersion.Reader property setter: assigning null to replace the reader VersionPair is rejected because a FormatVersion must always retain a valid reader version. The setter validates and then assigns to the _reader field.

Solutions

  1. Assign a valid VersionPair instead of null (e.g. new VersionPair(1, 0))
  2. Skip the assignment when the new value is null
  3. Use the constructor to build a fresh FormatVersion rather than mutating Reader to null

Example fix

// before
formatVersion.Reader = null; // throws ArgumentNullException
// after
if (newReader != null)
    formatVersion.Reader = newReader;
Defensive patterns

Strategy: type-guard

Validate before calling

if (newReader != null) formatVersion.Reader = newReader;

Type guard

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

Try / catch

try { formatVersion.Reader = value; } catch (ArgumentNullException) { /* null assignment rejected */ }

Prevention

When it happens

Trigger: formatVersion.Reader = null; on an existing FormatVersion instance, typically in version-update or migration code.

Common situations: Code that clears versions before setting new ones, or data-binding/initialization paths that assign null by default.

Related errors


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

Appendix: source

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

        #region Public Properties

#if !PBTCOMPILER
        /// <summary>
        /// reader version
        /// </summary>
        public VersionPair ReaderVersion
        {
            get
            {
                return _reader;
            }

            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }

                _reader = value;
            }
        }

        /// <summary>
        /// writer version
        /// </summary>
        public VersionPair WriterVersion
        {
            get
            {
                return _writer;
            }
            set
            {
                if (value == null)

View on GitHub (pinned to 81131a70a4)