{"record":{"id":"c06427f3a431d639","repo":"dotnet/wpf","slug":"sr-unknownreferencecomponenttype","errorCode":null,"errorMessage":"SR.UnknownReferenceComponentType","messagePattern":"SR\\.UnknownReferenceComponentType","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileReference.cs","lineNumber":212,"sourceCode":"                            storageList = new StringCollection();\n\n                        String str = ContainerUtilities.ReadByteLengthPrefixedDWordPaddedUnicodeString(reader, out byteLength);\n                        bytesRead += byteLength;\n                        storageList.Add(str);\n} break;\n                    case RefComponentType.Stream:\n                    {\n                        if (streamName != null)\n                            throw new FileFormatException(\n                                SR.CFRCorruptMultiStream);\n\n                        streamName = ContainerUtilities.ReadByteLengthPrefixedDWordPaddedUnicodeString(reader, out byteLength);\n                        bytesRead += byteLength;\n                    } break;\n\n                    // we don't handle these types yet\n                    default:\n                        throw new FileFormatException(\n                            SR.UnknownReferenceComponentType);\n                }\n\n                --entryCount;\n            }\n\n            CompoundFileReference newRef = null;\n\n            // stream or storage?\n            if (streamName == null)\n            {\n                newRef = new CompoundFileStorageReference(\n                    ContainerUtilities.ConvertStringArrayPathToBackSlashPath(storageList));\n            }\n            else\n                newRef = new CompoundFileStreamReference(\n                    ContainerUtilities.ConvertStringArrayPathToBackSlashPath(storageList, streamName));\n","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileReference.cs#L194-L230","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-acquire or re-export the file from a trusted source; the byte stream is likely corrupt or from an unsupported writer.","Confirm the file version/writer is supported by the .NET/WPF version in use; upgrade the runtime if a newer format is expected.","Catch FileFormatException around the Load/open call and fail gracefully with a 'not a supported compound file' message.","If you control the writer, only emit Storage and Stream component types."],"exampleFix":"// before\nvar reference = CompoundFileReference.Load(reader);\n// after\nCompoundFileReference reference;\ntry { reference = CompoundFileReference.Load(reader); }\ncatch (FileFormatException ex) { throw new InvalidDataException(\"Unknown reference component type; file may be from an unsupported writer.\", ex); }","handlingStrategy":"try-catch","validationCode":"byte[] head = new byte[4]; if (stream.Read(head, 0, 4) < 4) throw new InvalidDataException(\"Truncated reference header.\");","typeGuard":"static bool IsSupportedComponentType(byte t) => t == (byte)RefComponentType.Storage || t == (byte)RefComponentType.Stream;","tryCatchPattern":"try { return CompoundFileReference.Load(reader); }\ncatch (FileFormatException) { return null; /* unsupported/corrupt type */ }","preventionTips":["Validate file provenance and version before parsing","Treat unknown format bytes as corrupt input and fail fast","Keep .NET/WPF runtime updated for newer format support"],"tags":["file-corruption","fileformat","unsupported-value","packaging"],"backgroundTag":"unsupported-enum-value","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"}