dotnet/wpf · error · FileFormatException

SR.UnknownReferenceComponentType

Error message

SR.UnknownReferenceComponentType

What it means

CompoundFileReference.Load() read a component-type byte that is not one of the handled RefComponentType values (Storage/Stream). The comment in the source states these types are simply not handled, so the parser treats the record as invalid and throws FileFormatException. This means either the data is corrupt or it uses a newer/unknown format revision.

Solutions

  1. Re-acquire or re-export the file from a trusted source; the byte stream is likely corrupt or from an unsupported writer.
  2. Confirm the file version/writer is supported by the .NET/WPF version in use; upgrade the runtime if a newer format is expected.
  3. Catch FileFormatException around the Load/open call and fail gracefully with a 'not a supported compound file' message.
  4. If you control the writer, only emit Storage and Stream component types.

Example fix

// before
var reference = CompoundFileReference.Load(reader);
// after
CompoundFileReference reference;
try { reference = CompoundFileReference.Load(reader); }
catch (FileFormatException ex) { throw new InvalidDataException("Unknown reference component type; file may be from an unsupported writer.", ex); }
Defensive patterns

Strategy: try-catch

Validate before calling

byte[] head = new byte[4]; if (stream.Read(head, 0, 4) < 4) throw new InvalidDataException("Truncated reference header.");

Type guard

static bool IsSupportedComponentType(byte t) => t == (byte)RefComponentType.Storage || t == (byte)RefComponentType.Stream;

Try / catch

try { return CompoundFileReference.Load(reader); }
catch (FileFormatException) { return null; /* unsupported/corrupt type */ }

Prevention

When it happens

Trigger: Loading a compound-file reference whose serialized component-type discriminant falls into the default branch — i.e. a byte value outside the known RefComponentType set.

Common situations: Corrupted or maliciously crafted compound files, files from future or third-party writers using additional component types, or bit rot in stored documents opened via System.IO.Packaging compound-file support.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileReference.cs:212

                            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?
            if (streamName == null)
            {
                newRef = new CompoundFileStorageReference(
                    ContainerUtilities.ConvertStringArrayPathToBackSlashPath(storageList));
            }
            else
                newRef = new CompoundFileStreamReference(
                    ContainerUtilities.ConvertStringArrayPathToBackSlashPath(storageList, streamName));

View on GitHub (pinned to 81131a70a4)