{"record":{"id":"c5331f10f7c88d0f","repo":"dotnet/wpf","slug":"sr-wrongdocumentpropertyvarianttype-propid-fmtid-actual-vt","errorCode":null,"errorMessage":"SR.WrongDocumentPropertyVariantType (propId, fmtid, actual vt, expected vt)","messagePattern":"SR\\.WrongDocumentPropertyVariantType \\(propId, fmtid, actual vt, expected vt\\)","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/StorageBasedPackageProperties.cs","lineNumber":531,"sourceCode":"            object obj = null;\n\n            PROPSPEC[] propSpecs = new PROPSPEC[1];\n            PROPVARIANT[] vals = new PROPVARIANT[1];\n\n            propSpecs[0].propType = (uint)PropSpecType.Id;\n            propSpecs[0].union.propId = propId;\n\n            VARTYPE vtExpected = GetVtFromPropId(fmtid, propId);\n\n            int hresult = ps.ReadMultiple(1, propSpecs, vals);\n\n            if (hresult == SafeNativeCompoundFileConstants.S_OK)\n            {\n                try\n                {\n                    if (vals[0].vt != vtExpected)\n                    {\n                        throw new FileFormatException(\n                                        SR.Format(\n                                            SR.WrongDocumentPropertyVariantType,\n                                            propId,\n                                            fmtid.ToString(),\n                                            vals[0].vt,\n                                            vtExpected\n                                            )\n                                        );\n                    }\n\n                    switch (vals[0].vt)\n                    {\n                        case VARTYPE.VT_LPSTR:\n                            //\n                            // We store string properties as CP_ACP or UTF-8. \n                            // But no matter which format the string was encoded, we always use the UTF-8\n                            // encoder/decoder to decode the byte array, because the UTF-8 code of an ASCII\n                            // string is the same as the ASCII string.","sourceCodeStart":513,"sourceCodeEnd":549,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/StorageBasedPackageProperties.cs#L513-L549","documentation":"FileFormatException with message WrongDocumentPropertyVariantType(propId, fmtid, actual vt, expected vt) thrown by StorageBasedPackageProperties.GetOleProperty when an OLE compound-file property (e.g. document Title or Keywords) is read and its stored VARTYPE differs from the VARTYPE the caller requested. The package-properties reader treats the type mismatch as a corrupt/invalid property stream rather than coercing.","triggerScenarios":"Reading package properties (PackageProperties.Title/Subject/Creator/Keywords/Description/LastModifiedBy) from a document whose OLE property set stores the property with a different variant type than expected — e.g. VT_LPWSTR stored where VT_LPSTR is expected for that propId, or an integer where a string is required.","commonSituations":"Documents produced by third-party generators that write non-standard property types; files edited by older/other office suites with divergent property-set encoding; corrupted \u0005SummaryInformation streams.","solutions":["Open the document in a compliant producer and re-save to normalize the property types.","Inspect the OLE property set (fmtid/propId) with a tool like PropBadge or Open XML SDK to confirm the stored vt.","Wrap property reads in try-catch for FileFormatException and treat as missing metadata.","If you control writing code, use the same VARTYPE the reader expects for each propId."],"exampleFix":"// before\nstring title = package.PackageProperties.Title; // throws on vt mismatch\n// after\nstring title;\ntry { title = package.PackageProperties.Title; }\ncatch (FileFormatException) { title = null; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { title = pkg.PackageProperties.Title; }\ncatch (FileFormatException ex) when (ex.Message.Contains(\"variant type\") || ex.Message.Contains(\"WrongDocumentPropertyVariantType\")) { title = null; }","preventionTips":["Re-save third-party documents with a compliant producer before reading properties","Treat package metadata as untrusted input","Validate property streams during package import"],"tags":["fileformatexception","ole-properties","metadata","vartype"],"backgroundTag":"type-mismatch","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"}