dotnet/wpf · error · ArgumentNullException

Value cannot be null. (Parameter 'featureId')

Error message

Value cannot be null. (Parameter 'featureId')

What it means

ArgumentNullException from the FormatVersion constructor: a FormatVersion describes one feature's writer/reader/updater versions in the compound-file DataSpace version block, and a null featureId string cannot identify the feature, so construction fails fast.

Solutions

  1. Pass a non-null, non-empty feature ID string (e.g. "DataSpace")
  2. Initialize the featureId variable before constructing FormatVersion
  3. When parsing files, reject or skip version records with missing feature IDs before constructing

Example fix

// before
var fv = new FormatVersion(featureId, w, r, u); // featureId was null
// after
if (string.IsNullOrEmpty(featureId)) featureId = "DataSpace";
var fv = new FormatVersion(featureId, w, r, u);
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

static bool IsValidFeatureId(string s) => !string.IsNullOrEmpty(s);

Prevention

When it happens

Trigger: Calling new FormatVersion(null, writerVersion, readerVersion, updaterVersion) directly, or indirectly through code that builds version records with an uninitialized feature ID.

Common situations: Custom DataSpace/transform tooling constructing FormatVersion records; deserializing version blocks where the feature-id field was empty or missing.

Related errors


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

Appendix: source

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

            : this(featureId, version, version, version)
        {
        }

        /// <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;
        }

View on GitHub (pinned to 81131a70a4)