dotnet/wpf · error · FileFormatException
SR.InvalidDocumentPropertyVariantType (vt)
Error message
SR.InvalidDocumentPropertyVariantType (vt)
What it means
FileFormatException with message InvalidDocumentPropertyVariantType(vt) thrown by GetOleProperty when the stored OLE property variant type is valid enough to read but falls outside the set of VARTYPEs the conversion switch handles (string, int, short, bool, filetime, etc.). The reader cannot convert the value to a CLR type and reports the raw vt.
Solutions
- Re-save the file with a mainstream producer to rewrite properties as standard variant types.
- Remove the offending custom property from the document.
- Catch FileFormatException around PackageProperties access and fall back to defaults.
- Read the raw property set yourself if the exotic type is meaningful to you.
Example fix
// before
var creator = pkg.PackageProperties.Creator; // throws on unhandled vt
// after
string creator = null;
try { creator = pkg.PackageProperties.Creator; }
catch (FileFormatException) { /* unsupported vt */ } Defensive patterns
Strategy: try-catch
Try / catch
try { value = pkg.PackageProperties.Subject; }
catch (FileFormatException) { value = null; /* unsupported stored vt */ } Prevention
- Normalize documents through a re-save pipeline before metadata extraction
- Strip exotic custom properties from ingested files
- Centralize property reads behind a safe accessor with fallbacks
When it happens
Trigger: Reading a package property whose stored vt is an unhandled variant (e.g. VT_ARRAY, VT_VARIANT, VT_BLOB, VT_CY) for the given propId — the switch in GetOleProperty hits its default case.
Common situations: Custom or exotic property sets written by non-Microsoft producers; properties promoted by document management systems into the summary-information stream with unusual types.
Related errors
- SR.WrongDocumentPropertyVariantType (propId, fmtid, actual…
- SR.UnknownDocumentProperty (fmtid, propId)
- FileFormatException(new Uri(fileName…
- FileFormatException(new Uri(_reader.BaseURI…
- Image_EncoderNoGlobalMetadata
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e4d938bbaa393d0c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/StorageBasedPackageProperties.cs:579
int nLen = ansiString.Length;
byte[] byteArray = new byte[nLen];
Marshal.Copy(pszVal, byteArray, 0, nLen);
obj = UTF8Encoding.UTF8.GetString(byteArray);
break;
case VARTYPE.VT_FILETIME:
//
// DateTime doesn't have a conversion from FILETIME. It has a
// misleadingly named "FromFileTime" method that actually wants
// a long. So...
//
obj = new Nullable<DateTime>(DateTime.FromFileTime(vals[0].union.hVal));
break;
default:
throw new FileFormatException(
SR.Format(SR.InvalidDocumentPropertyVariantType, vals[0].vt));
}
}
finally
{
// "by design" ignored return value
SafeNativeCompoundFileMethods.SafePropVariantClear(ref vals[0]);
}
}
else if (hresult == SafeNativeCompoundFileConstants.S_FALSE)
{
// Do nothing -- return the null object reference.
}
else
{
SecurityHelper.ThrowExceptionForHR(hresult);
}
View on GitHub (pinned to 81131a70a4)