dotnet/wpf · error · ArgumentException

This combination of flags is not supported.

Error message

This combination of flags is not supported.

What it means

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.

Solutions

  1. Use supported combinations: FileMode.Create/CreateNew/OpenOrCreate with FileAccess.ReadWrite or Write
  2. Remove exotic flags or sharing options from the call
  3. Catch ArgumentException and retry with FileMode.Create and FileAccess.ReadWrite

Example fix

// before
var s = streamInfo.Create(name, FileMode.Append, FileAccess.Read);
// after
var s = streamInfo.Create(name, FileMode.Create, FileAccess.ReadWrite);
Defensive patterns

Strategy: validation

Validate before calling

bool supported = mode is FileMode.Create or FileMode.CreateNew or FileMode.OpenOrCreate or FileMode.Open or FileMode.Truncate;
if (!supported) throw new ArgumentException($"Unsupported FileMode {mode} for compound file streams.");

Try / catch

try { streamInfo.Create(name, mode, access); }
catch (ArgumentException ex) when (ex.Message.Contains("flags")) { stream = streamInfo.Create(name, FileMode.Create, FileAccess.ReadWrite); }

Prevention

When it happens

Trigger: 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).

Common situations: Passing unusual FileMode values (Append), combining FileAccess with sharing modes the compound file implementation does not accept; porting code that used raw STGM flags.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/24cf855250080662. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/CompoundFile/StreamInfo.cs:600

        {
            IStream createdStream = null;
            int nativeCallErrorCode = 0;

            if( !parentStorage.Exists )
            {
                parentStorage.Create();
            }

            nativeCallErrorCode = parentStorage.SafeIStorage.CreateStream(
                name,
                mode,
                0,
                0,
                out createdStream );

            if( SafeNativeCompoundFileConstants.STG_E_INVALIDFLAG == nativeCallErrorCode )
            {
                throw new ArgumentException(
                    SR.StorageFlagsUnsupported);
            }
            else if ( SafeNativeCompoundFileConstants.S_OK != nativeCallErrorCode )
            {
                throw new IOException(
                    SR.UnableToCreateStream,
                    new COMException( 
                        SR.Format(SR.NamedAPIFailure, "IStorage.CreateStream"),
                        nativeCallErrorCode ));
            }

            // Parent storage has changed - invalidate all standing enuemrators
            parentStorage.InvalidateEnumerators();
        
            return createdStream;
        }

        /// <summary>

View on GitHub (pinned to 81131a70a4)