dotnet/wpf · error · FileFormatException
SR.CFRCorruptMultiStream
Error message
SR.CFRCorruptMultiStream
What it means
CompoundFileReference.Load() parses a serialized reference and found a second Stream component in a single reference entry, which the format forbids. A valid compound-file reference may name at most one storage and one stream; encountering a second stream means the serialized data is malformed or truncated/corrupted. The library fails fast with FileFormatException rather than misinterpreting the bytes.
Solutions
- Verify the file is not corrupted: re-obtain it from the source and compare checksums or re-download in binary mode.
- Validate that the file was written by a conformant compound-file writer; re-generate it with the official packaging APIs (System.IO.Packaging / ZipPackage or valid OCG/CPF writer).
- Wrap the Load call in try/catch for FileFormatException and treat it as invalid input, showing a user-facing 'file is corrupted' message.
- If constructing references programmatically, do not serialize multiple Stream components into one reference.
Example fix
// before
var reference = CompoundFileReference.Load(binaryReader); // throws FileFormatException on corrupt data
// after
CompoundFileReference reference;
try { reference = CompoundFileReference.Load(binaryReader); }
catch (FileFormatException) { throw new InvalidDataException("The compound file reference data is corrupt."); } Defensive patterns
Strategy: try-catch
Validate before calling
if (reader.BaseStream.Length - reader.BaseStream.Position < 8) throw new InvalidDataException("Not enough bytes for a compound-file reference."); Type guard
static bool IsValidCompoundFileData(Stream s) => s != null && s.CanRead && s.Length > 0;
Try / catch
try { var r = CompoundFileReference.Load(reader); }
catch (FileFormatException ex) { log.Warn(ex, "Corrupt compound-file reference"); throw new InvalidDataException("File is corrupt.", ex); } Prevention
- Verify file integrity (checksum/hash) before opening compound files
- Always transfer/store these files in binary mode
- Re-download corrupted files from the source instead of retrying
- Only write compound files with the official packaging APIs
When it happens
Trigger: Calling CompoundFileReference.Load (or loading a compound-file container that stores references) over a byte stream whose reference record lists Stream component type more than once for one entry.
Common situations: Hand-edited or corrupted compound files, files produced by buggy third-party writers, files truncated by incomplete downloads or transfer in text mode, or fuzzed input to code that opens XPS/compound-file packages.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- SR.UnknownReferenceComponentType
- String format is not valid.
- ' ' cannot contain the path delimiter: ' '.
- ' ' cannot start with the reserved character range…
- ' ' ID is not a valid XSD ID.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/6c564a2e57c35a03.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileReference.cs:203
switch (refType)
{
case RefComponentType.Storage:
{
if (streamName != null)
throw new FileFormatException(
SR.CFRCorruptStgFollowStm);
if (storageList == null)
storageList = new StringCollection();
String str = ContainerUtilities.ReadByteLengthPrefixedDWordPaddedUnicodeString(reader, out byteLength);
bytesRead += byteLength;
storageList.Add(str);
} break;
case RefComponentType.Stream:
{
if (streamName != null)
throw new FileFormatException(
SR.CFRCorruptMultiStream);
streamName = ContainerUtilities.ReadByteLengthPrefixedDWordPaddedUnicodeString(reader, out byteLength);
bytesRead += byteLength;
} break;
// we don't handle these types yet
default:
throw new FileFormatException(
SR.UnknownReferenceComponentType);
}
--entryCount;
}
CompoundFileReference newRef = null;
// stream or storage?View on GitHub (pinned to 81131a70a4)