dotnet/wpf · error · NotSupportedException
SR.UnsupportedTypeEncounteredWhenBuildingStgEnum
Error message
SR.UnsupportedTypeEncounteredWhenBuildingStgEnum
What it means
While building the storage enumerator, CompoundFileStorageInfo (StorageInfo) walks IEnumSTATSTG elements and maps each type to a StorageInfo or StreamInfo; encountering a STATSTG type that is neither STGTY_STORAGE nor STGTY_STREAM throws NotSupportedException with SR.UnsupportedTypeEncounteredWhenBuildingStgEnum. This guards against unknown/lock-only element types in the compound file.
Solutions
- Validate/repair the compound file by opening and re-saving it in the owning application.
- Skip broken elements by catching NotSupportedException around enumeration and continuing with the valid children.
- Enumerate via the native IStorage directly and filter on dwType yourself.
- Regenerate the container with the supported .NET Packaging writer.
Example fix
// before
foreach (var s in storageInfo.GetStorageInfos()) { ... } // throws NotSupportedException
// after
List<StorageInfo> storages = new List<StorageInfo>();
try { storages.AddRange(storageInfo.GetStorageInfos()); }
catch (NotSupportedException) { /* skip unsupported element types */ } Defensive patterns
Strategy: try-catch
Validate before calling
// pre-validate container by opening it fully before enumerating using var test = StorageRoot.OpenOnStream(stream, FileMode.Open, FileAccess.Read, null); _ = test.GetStorageInfos().ToList();
Prevention
- Validate third-party compound files before enumerating.
- Keep source files intact; work on copies when containers come from untrusted writers.
- Filter enumeration through your own IStorage walk if you need to tolerate unknown types.
When it happens
Trigger: Enumerating a storage whose IEnumSTATSTG yields an element of an unexpected type (e.g. STGTY_LOCKBYTES or corrupt type bytes) via GetStorageInfos/GetStreamInfos or the child collections.
Common situations: Corrupt or hand-crafted compound files; files produced by third-party OLE writers containing lockbyte entries; bitwise file damage making the type field invalid.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SR.CanNotCreateContainerOnReadOnlyStream
- SR.CanNotCreateStorageRootOnNonReadableStream
- SR.CanNotDelete
- SR.CanNotOnNonExistStorage
- SR.CanNotOpenStorage
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/65ff372bc0a9bc79.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs:1357
if( desiredArrayType == EnumeratorTypes.Everything ||
desiredArrayType == EnumeratorTypes.OnlyStorages )
{
// Add reference to a storage to enumerator array
storageElems.Add(new StorageInfo(this, externalName));
}
}
else if( SafeNativeCompoundFileConstants.STGTY_STREAM == enumElement.type )
{
if( desiredArrayType == EnumeratorTypes.Everything ||
desiredArrayType == EnumeratorTypes.OnlyStreams )
{
// Add reference to a stream to enumerator array
storageElems.Add(new StreamInfo(this, externalName));
}
}
else
{
throw new NotSupportedException(
SR.UnsupportedTypeEncounteredWhenBuildingStgEnum);
}
// Move on to the next element
safeIEnumSTATSTG.Next( 1, out enumElement, out actual );
}
core.validEnumerators[ desiredArrayType ] = storageElems;
// Release IEnumSTATSTG
((IDisposable) safeIEnumSTATSTG).Dispose();
safeIEnumSTATSTG = null;
}
Debug.Assert( null != core.validEnumerators[ desiredArrayType ],
"We failed to ensure the proper array for enumeration" );
}
}View on GitHub (pinned to 81131a70a4)