{"record":{"id":"32debd7d3a46df64","repo":"dotnet/wpf","slug":"value-cannot-be-null-parameter-writerversion","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'writerVersion')","messagePattern":"Value cannot be null\\. \\(Parameter 'writerVersion'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/FormatVersion.cs","lineNumber":69,"sourceCode":"        }\n\n        /// <summary>\n        /// Constructor for FormatVersion with given featureId and reader, updater,\n        /// and writer version\n        /// </summary>\n        /// <param name=\"featureId\">feature identifier</param>\n        /// <param name=\"writerVersion\">Writer Version</param>\n        /// <param name=\"readerVersion\">Reader Version</param>\n        /// <param name=\"updaterVersion\">Updater Version</param>\n        public FormatVersion(String featureId,\n                                VersionPair writerVersion,\n                                VersionPair readerVersion,\n                                VersionPair updaterVersion)\n        {\n            if (featureId == null)\n                throw new ArgumentNullException(nameof(featureId));\n            if (writerVersion == null)\n                throw new ArgumentNullException(nameof(writerVersion));\n            if (readerVersion == null)\n                throw new ArgumentNullException(nameof(readerVersion));\n            if (updaterVersion == null)\n                throw new ArgumentNullException(nameof(updaterVersion));\n\n            if (featureId.Length == 0)\n            {\n                throw new ArgumentException(SR.ZeroLengthFeatureID);\n            }\n\n            _featureIdentifier = featureId;\n            _reader = readerVersion;\n            _updater = updaterVersion;\n            _writer = writerVersion;\n        }\n\n        #endregion Constructors\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/FormatVersion.cs#L51-L87","documentation":"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.","triggerScenarios":"new FormatVersion(featureId, null, readerVersion, updaterVersion) — passing an uninitialized writer VersionPair.","commonSituations":"Building DataSpace version blocks in custom packaging code where the writer version was not initialized; refactoring code that dropped the writer version argument.","solutions":["Provide a valid VersionPair, e.g. new VersionPair(1, 0), for writerVersion","Initialize the writerVersion variable before calling the constructor","Default to the library's current versions (writer/reader/updater 1.0) when unsure"],"exampleFix":"// before\nvar fv = new FormatVersion(id, null, reader, updater);\n// after\nvar writer = new VersionPair(1, 0);\nvar fv = new FormatVersion(id, writer, reader, updater);","handlingStrategy":"validation","validationCode":"if (writerVersion == null) throw new ArgumentException(\"writerVersion is required\");\nvar fv = new FormatVersion(featureId, writerVersion, readerVersion, updaterVersion);","typeGuard":"static bool IsValidVersion(VersionPair v) => v != null;","tryCatchPattern":null,"preventionTips":["Default missing versions to new VersionPair(1, 0)","Check all three version arguments for null before construction","Keep version pairs in a single record struct so they are initialized together"],"tags":["null-argument","wpf","packaging","version"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}