dotnet/wpf · error · IOException
DataSpace map entry is not valid.
Error message
DataSpace map entry is not valid.
What it means
After each DataSpaceMap entry is parsed, the declared entryLength is compared against the number of bytes actually consumed (length field + container reference + label). A mismatch throws IOException with SR.DataSpaceMapEntryInvalid, because a well-formed writer must make the declared length match the real entry size exactly.
Solutions
- Re-save the package with the reference implementation or a conformant writer so entry lengths are recomputed correctly.
- Inspect the DataSpaceMap with a binary editor and fix entryLength values to match actual entry byte counts.
- Validate each map entry (declared length == 4 + reference size + label byte count) before handing the file to the library.
- Catch IOException during Package.Open and treat it as a malformed package; recover content via repair tooling.
Example fix
// before // writer: entryLength = label.Length (chars) -> mismatch, IOException // after // writer: entryLength = 4 + referenceSize + Encoding.Unicode.GetByteCount(label)
Defensive patterns
Strategy: try-catch
Validate before calling
// for each map entry: entryLength must equal 4 + referenceSize + labelByteCount before open
Try / catch
try { package = Package.Open(path); }
catch (IOException e) when (e.Message == SR.DataSpaceMapEntryInvalid)
{
throw new InvalidDataException("DataSpaceMap entry lengths do not match actual entry sizes.", e);
} Prevention
- Compute entryLength as 4 + reference size + UTF-16 byte count of the label when writing.
- Re-save third-party packages with a reference writer before relying on them.
- Add round-trip write/read tests for DataSpaceMap entries in tools you build.
When it happens
Trigger: Opening a package whose DataSpaceMap entry declares a byte length that differs from the actual parsed size — e.g. the entry's label or container reference was written with wrong encoding/size, the entry was hand-patched, or a buggy writer miscounted.
Common situations: Packages produced by third-party OPC writers that miscalculate entry lengths; files modified by tools that inserted/removed bytes without updating entryLength; Unicode label strings saved with wrong encoding length.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- File contains corrupted data.
- SR.VersionUpdateFailure
- Data space transform stack includes undefined transform…
- Document does not contain a package.
- Document does not contain any rights management-protected…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e4921a8a07874f13.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/DataSpaceManager.cs:1079
if (entryLength < 0)
throw new FileFormatException(SR.CorruptedData);
totalBytesRead = 4; // entryLength
// Read the container reference entry
CompoundFileReference entryRef =
CompoundFileReference.Load( dataSpaceMapReader, out bytesRead );
checked { totalBytesRead += bytesRead; }
// Read data space string and add to data space mapping table
string label = CU.ReadByteLengthPrefixedDWordPaddedUnicodeString(dataSpaceMapReader, out bytesRead);
checked { totalBytesRead += bytesRead; }
_dataSpaceMap[entryRef] = label;
// Verify entryLength against what was actually read:
if (entryLength != totalBytesRead)
{
throw new IOException(SR.DataSpaceMapEntryInvalid);
}
}
}
}
}
}
/// <summary>
/// Write the data space mapping table to underlying storage.
/// </summary>
private void WriteDataSpaceMap()
{
ThrowIfIncorrectUpdaterVersion();
StorageInfo dataSpaceStorage =
new StorageInfo( _associatedStorage, DataSpaceStorageName );
StreamInfo dataSpaceMapStreamInfo =
new StreamInfo ( dataSpaceStorage, DataSpaceMapTableName );View on GitHub (pinned to 81131a70a4)