{"record":{"id":"65ff372bc0a9bc79","repo":"dotnet/wpf","slug":"sr-unsupportedtypeencounteredwhenbuildingstgenum","errorCode":null,"errorMessage":"SR.UnsupportedTypeEncounteredWhenBuildingStgEnum","messagePattern":"SR\\.UnsupportedTypeEncounteredWhenBuildingStgEnum","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs","lineNumber":1357,"sourceCode":"                    if( desiredArrayType == EnumeratorTypes.Everything ||\n                        desiredArrayType == EnumeratorTypes.OnlyStorages )\n                    {\n                        // Add reference to a storage to enumerator array\n                        storageElems.Add(new StorageInfo(this, externalName));\n                    }\n                }\n                else if( SafeNativeCompoundFileConstants.STGTY_STREAM == enumElement.type )\n                {\n                    if( desiredArrayType == EnumeratorTypes.Everything ||\n                        desiredArrayType == EnumeratorTypes.OnlyStreams )\n                    {\n                        // Add reference to a stream to enumerator array\n                         storageElems.Add(new StreamInfo(this, externalName));\n                    }\n                }\n                else\n                {\n                    throw new NotSupportedException(\n                        SR.UnsupportedTypeEncounteredWhenBuildingStgEnum);\n                }\n\n                // Move on to the next element\n                safeIEnumSTATSTG.Next( 1, out enumElement, out actual );\n            }\n\n            core.validEnumerators[ desiredArrayType ] = storageElems;\n\n            // Release IEnumSTATSTG\n            ((IDisposable) safeIEnumSTATSTG).Dispose();\n            safeIEnumSTATSTG = null;\n        }\n\n        Debug.Assert( null != core.validEnumerators[ desiredArrayType ],\n            \"We failed to ensure the proper array for enumeration\" );\n    }\n}","sourceCodeStart":1339,"sourceCodeEnd":1375,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StorageInfo.cs#L1339-L1375","documentation":"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.","triggerScenarios":"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.","commonSituations":"Corrupt or hand-crafted compound files; files produced by third-party OLE writers containing lockbyte entries; bitwise file damage making the type field invalid.","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."],"exampleFix":"// before\nforeach (var s in storageInfo.GetStorageInfos()) { ... } // throws NotSupportedException\n// after\nList<StorageInfo> storages = new List<StorageInfo>();\ntry { storages.AddRange(storageInfo.GetStorageInfos()); }\ncatch (NotSupportedException) { /* skip unsupported element types */ }","handlingStrategy":"try-catch","validationCode":"// pre-validate container by opening it fully before enumerating\nusing var test = StorageRoot.OpenOnStream(stream, FileMode.Open, FileAccess.Read, null);\n_ = test.GetStorageInfos().ToList();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["io","compound-file","enumeration","corrupt-file"],"backgroundTag":"unsupported-operation","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"}