dotnet/wpf · error · FileFormatException

File contains data in format version

Error message

File contains data in format version {0}, but the software can only read that data in format version {1} or lower.

What it means

This FileFormatException is thrown by ThrowIfIncorrectReaderVersion when the data space information block's reader version is newer than DataSpaceCurrentReaderVersion supported by this build. The library can only read data-space metadata at or below its own supported format version, so files written by a newer implementation are rejected.

Solutions

  1. Open the package on a runtime whose data-space reader version is at least the file's recorded version (upgrade .NET/WPF).
  2. Re-save the package with the current (older) runtime or a tool targeting the supported format version.
  3. Check the package's data-space version info with a compound-file viewer to confirm the recorded reader version.
  4. Catch FileFormatException with the version message and guide users to upgrade rather than retrying.
Defensive patterns

Strategy: fallback

Validate before calling

// Check recorded reader version in the package metadata before opening (if pre-inspected):
bool readable = recordedReaderVersion <= currentDataReaderVersion;

Type guard

bool IsReadableVersion(Version fileReaderVersion, Version supported) => fileReaderVersion.Major <= supported.Major && fileReaderVersion <= supported;

Try / catch

try { package = Package.Open(path); }
catch (FileFormatException ex) when (ex.Message.StartsWith("File contains data in format version")) { Console.Error.WriteLine("Package needs a newer reader version; please upgrade the runtime."); throw; }

Prevention

When it happens

Trigger: Opening a package whose data space version block records a reader version greater than the current WPF data-space reader version; occurs during DataSpaceManager initialization via Package.Open.

Common situations: Packages produced by a newer runtime/version of the writing software being opened on an older .NET/WPF runtime, cross-platform transfers between framework versions, or tooling that bumps format versions.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs:1638

                                        DataSpaceCurrentUpdaterVersion
                                     );
        }
    }

    /// <summary>
    /// Verify that the current version of this class can read the DataSpace information in
    /// this file.
    /// </summary>
    /// <exception cref="FileFormatException">
    /// If the current version of this class cannot read the DataSpace information in this file.
    /// </exception>
    private void ThrowIfIncorrectReaderVersion()
    {
        EnsureDataSpaceVersionInformation();

        if (!_fileFormatVersion.IsReadableBy(DataSpaceCurrentReaderVersion))
        {
            throw new FileFormatException(
                            SR.Format(
                                SR.ReaderVersionError,
                                _fileFormatVersion.ReaderVersion,
                                DataSpaceCurrentReaderVersion
                                )
                            );
        }
    }

    /// <summary>
    /// Verify that the current version of this class can update the DataSpace information in
    /// this file.
    /// </summary>
    /// <exception cref="FileFormatException">
    /// If the current version of this class cannot update the DataSpace information in this file,
    /// or if the header information in the stream is corrupt.
    /// </exception>
    private void ThrowIfIncorrectUpdaterVersion()

View on GitHub (pinned to 81131a70a4)