{"record":{"id":"c4ce8da573db3c73","repo":"dotnet/wpf","slug":"value-cannot-be-null-parameter-version","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'version')","messagePattern":"Value cannot be null\\. \\(Parameter 'version'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/FormatVersion.cs","lineNumber":369,"sourceCode":"                return len;\n            }\n        }\n\n#if !PBTCOMPILER\n        /// <summary>\n        /// Check if a component with the given version can read this format version safely\n        /// </summary>\n        /// <param name=\"version\">version of a component</param>\n        /// <returns>true if this format version can be read safely by the component\n        /// with the given version, otherwise false</returns>\n        /// <remarks>\n        /// The given version is checked against ReaderVersion\n        /// </remarks>\n        public bool IsReadableBy(VersionPair version)\n        {\n            if (version == null)\n            {\n                throw new ArgumentNullException(nameof(version));\n            }\n\n            return (_reader <= version);\n        }\n\n        /// <summary>\n        /// Check if a component with the given version can update this format version safely\n        /// </summary>\n        /// <param name=\"version\">version of a component</param>\n        /// <returns>true if this format version can be updated safely by the component\n        /// with the given version, otherwise false</returns>\n        /// <remarks>\n        /// The given version is checked against UpdaterVersion\n        /// </remarks>\n        public bool IsUpdatableBy(VersionPair version)\n        {\n            if (version == null)\n            {","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/FormatVersion.cs#L351-L387","documentation":"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'.","triggerScenarios":"Calling formatVersion.IsReadableBy(null), typically when the version to test came from an uninitialized VersionPair variable or a lookup that returned null.","commonSituations":"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.","solutions":["Pass a valid non-null VersionPair, e.g. new VersionPair(major, minor)","Null-check the version argument before calling IsReadableBy and handle the null case explicitly","Fix the upstream parsing/lookup that produced a null VersionPair"],"exampleFix":"// before\nbool readable = fv.IsReadableBy(GetRequiredVersion());\n// after\nvar required = GetRequiredVersion();\nbool readable = required != null && fv.IsReadableBy(required);","handlingStrategy":"validation","validationCode":"bool readable = version != null && formatVersion.IsReadableBy(version);","typeGuard":"static bool IsUsableVersion(VersionPair v) => v != null;","tryCatchPattern":"try { readable = fv.IsReadableBy(v); }\ncatch (ArgumentNullException) { readable = false; }","preventionTips":["Initialize required-version constants at startup, not lazily","Treat null versions as 'not readable' in compatibility checks"],"tags":["null-argument","argumentnullexception","version-check","compound-file"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}