dotnet/wpf · error · ArgumentNullException

Value cannot be null. (Parameter 'version')

Error message

Value cannot be null. (Parameter 'version')

What it means

FormatVersion.IsReadableBy compares the given VersionPair against the file's ReaderVersion. A null argument cannot participate in the comparison, so the method throws ArgumentNullException with parameter name 'version'.

Solutions

  1. Pass a valid non-null VersionPair, e.g. new VersionPair(major, minor)
  2. Null-check the version argument before calling IsReadableBy and handle the null case explicitly
  3. Fix the upstream parsing/lookup that produced a null VersionPair

Example fix

// before
bool readable = fv.IsReadableBy(GetRequiredVersion());
// after
var required = GetRequiredVersion();
bool readable = required != null && fv.IsReadableBy(required);
Defensive patterns

Strategy: validation

Validate before calling

bool readable = version != null && formatVersion.IsReadableBy(version);

Type guard

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

Try / catch

try { readable = fv.IsReadableBy(v); }
catch (ArgumentNullException) { readable = false; }

Prevention

When it happens

Trigger: Calling formatVersion.IsReadableBy(null), typically when the version to test came from an uninitialized VersionPair variable or a lookup that returned null.

Common situations: Feature-checking a compound file's readability before opening it, where the application's required version object was never initialized or a parsing routine produced null instead of a VersionPair.

Related errors


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

Appendix: source

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

                return len;
            }
        }

#if !PBTCOMPILER
        /// <summary>
        /// Check if a component with the given version can read this format version safely
        /// </summary>
        /// <param name="version">version of a component</param>
        /// <returns>true if this format version can be read safely by the component
        /// with the given version, otherwise false</returns>
        /// <remarks>
        /// The given version is checked against ReaderVersion
        /// </remarks>
        public bool IsReadableBy(VersionPair version)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            return (_reader <= version);
        }

        /// <summary>
        /// Check if a component with the given version can update this format version safely
        /// </summary>
        /// <param name="version">version of a component</param>
        /// <returns>true if this format version can be updated safely by the component
        /// with the given version, otherwise false</returns>
        /// <remarks>
        /// The given version is checked against UpdaterVersion
        /// </remarks>
        public bool IsUpdatableBy(VersionPair version)
        {
            if (version == null)
            {

View on GitHub (pinned to 81131a70a4)