{"record":{"id":"c4c2237ad56ca1a2","repo":"dotnet/wpf","slug":"sr-format-sr-updaterversionerror-fileversion-updaterversion","errorCode":null,"errorMessage":"SR.Format(SR.UpdaterVersionError, _fileVersion.UpdaterVersion, _codeVersion)","messagePattern":"SR\\.Format\\(SR\\.UpdaterVersionError, _fileVersion\\.UpdaterVersion, _codeVersion\\)","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/VersionedStreamOwner.cs","lineNumber":257,"sourceCode":"        {\n            CheckDisposed();    // central location\n\n            if (!_writeOccurred)\n            {\n                // first try to read the format version\n                EnsureParsed();\n\n                if (_fileVersion == null)\n                {\n                    // stream is empty so write our version\n                    PersistVersion(_codeVersion);\n                }\n                else\n                {\n                    // file version found - ensure we are able to update it\n                    if (!_fileVersion.IsUpdatableBy(_codeVersion.UpdaterVersion))\n                    {\n                        throw new FileFormatException(\n                                        SR.Format(\n                                            SR.UpdaterVersionError,\n                                            _fileVersion.UpdaterVersion,\n                                            _codeVersion\n                                            )\n                                        );\n                    }\n\n                    // if our version is different than previous\n                    // updater then \"update\" the updater\n                    if (_codeVersion.UpdaterVersion != _fileVersion.UpdaterVersion)\n                    {\n                        _fileVersion.UpdaterVersion = _codeVersion.UpdaterVersion;\n                        PersistVersion(_fileVersion);\n                    }\n                }\n\n                _writeOccurred = true;","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/VersionedStreamOwner.cs#L239-L275","documentation":"FileFormatException (SR.UpdaterVersionError) thrown by VersionedStreamOwner.WriteAttempt when the version header already in the stream (_fileVersion.UpdaterVersion) is not updatable by the running code's version (_codeVersion.UpdaterVersion). It prevents writing data with a format newer than this code is allowed to produce — a forward-compatibility guard for compound-file versioned streams.","triggerScenarios":"Attempting Write, WriteByte, or SetLength on a versioned compound-file stream whose persisted FormatVersion carries an UpdaterVersion newer than the library's allowed updater version (e.g. the file was last written by a substantially newer runtime/tool).","commonSituations":"Files created by a newer .NET/WPF version opened for update by an older runtime; files round-tripped through different tools; deployment rollout skew where some machines run older runtimes against files written by newer ones.","solutions":["Open the file read-only instead of for update, or copy it to a new file if writes are required","Upgrade the runtime/library so its updater version matches or exceeds the file's version","Rewrite the file with a compatible writer version before performing updates","Catch FileFormatException around update attempts and route the file through a migration path"],"exampleFix":"// before: opening for update regardless of the file's version\nusing (var fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite))\n{\n    versionedStream.Write(data, 0, data.Length); // UpdaterVersionError\n}\n// after: open read-only when only reading, or handle the version mismatch\nusing (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))\n{\n    versionedStream.Read(buffer, 0, buffer.Length); // reads are governed by ReaderVersion instead\n}","handlingStrategy":"try-catch","validationCode":"// Open the file only for reading if updates are not strictly required\nbool canAttemptUpdate = CanOpenReadWrite(path) && FileWasWrittenByCompatibleWriter(path); // compare recorded UpdaterVersion with your runtime's","typeGuard":null,"tryCatchPattern":"try\n{\n    versionedStream.Write(data, 0, data.Length);\n}\ncatch (FileFormatException ex) when (ex.Message.Contains(\"update\") || ex.Message.Contains(\"version\"))\n{\n    // fall back: copy to a new file and rewrite, or ask the user to upgrade\n    CopyAndRewriteWithCompatibleWriter();\n}","preventionTips":["Align framework/tooling versions across machines that share compound files","Open files read-only unless an update is required","Track which writer version produced each file","During rollouts, migrate files to the new format before retiring old runtimes"],"tags":["versioning","compatibility","write","wpf"],"backgroundTag":"incompatible-source-type","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"}