{"record":{"id":"24cf855250080662","repo":"dotnet/wpf","slug":"this-combination-of-flags-is-not-supported","errorCode":null,"errorMessage":"This combination of flags is not supported.","messagePattern":"This combination of flags is not supported\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs","lineNumber":600,"sourceCode":"        {\n            IStream createdStream = null;\n            int nativeCallErrorCode = 0;\n\n            if( !parentStorage.Exists )\n            {\n                parentStorage.Create();\n            }\n\n            nativeCallErrorCode = parentStorage.SafeIStorage.CreateStream(\n                name,\n                mode,\n                0,\n                0,\n                out createdStream );\n\n            if( SafeNativeCompoundFileConstants.STG_E_INVALIDFLAG == nativeCallErrorCode )\n            {\n                throw new ArgumentException(\n                    SR.StorageFlagsUnsupported);\n            }\n            else if ( SafeNativeCompoundFileConstants.S_OK != nativeCallErrorCode )\n            {\n                throw new IOException(\n                    SR.UnableToCreateStream,\n                    new COMException( \n                        SR.Format(SR.NamedAPIFailure, \"IStorage.CreateStream\"),\n                        nativeCallErrorCode ));\n            }\n\n            // Parent storage has changed - invalidate all standing enuemrators\n            parentStorage.InvalidateEnumerators();\n        \n            return createdStream;\n        }\n\n        /// <summary>","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs#L582-L618","documentation":"CreateStreamOnParentIStorage invokes the COM IStorage.CreateStream native call. If the COM layer returns STG_E_INVALIDFLAG, the flags passed (access/mode combination) are not supported by the underlying structured storage implementation and an ArgumentException is thrown.","triggerScenarios":"Calling StreamInfo.Create or GetStream with a FileMode/FileAccess/StreamInfo flags combination that translates to flags IStorage.CreateStream rejects (e.g. unsupported sharing or transaction flags).","commonSituations":"Passing unusual FileMode values (Append), combining FileAccess with sharing modes the compound file implementation does not accept; porting code that used raw STGM flags.","solutions":["Use supported combinations: FileMode.Create/CreateNew/OpenOrCreate with FileAccess.ReadWrite or Write","Remove exotic flags or sharing options from the call","Catch ArgumentException and retry with FileMode.Create and FileAccess.ReadWrite"],"exampleFix":"// before\nvar s = streamInfo.Create(name, FileMode.Append, FileAccess.Read);\n// after\nvar s = streamInfo.Create(name, FileMode.Create, FileAccess.ReadWrite);","handlingStrategy":"validation","validationCode":"bool supported = mode is FileMode.Create or FileMode.CreateNew or FileMode.OpenOrCreate or FileMode.Open or FileMode.Truncate;\nif (!supported) throw new ArgumentException($\"Unsupported FileMode {mode} for compound file streams.\");","typeGuard":null,"tryCatchPattern":"try { streamInfo.Create(name, mode, access); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"flags\")) { stream = streamInfo.Create(name, FileMode.Create, FileAccess.ReadWrite); }","preventionTips":["Stick to documented FileMode/FileAccess combinations for compound files","Avoid FileMode.Append and exotic sharing flags","Wrap storage creation in one helper with vetted parameter sets"],"tags":["flags","com-interop","packaging"],"backgroundTag":"invalid-flag-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"}