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
- 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
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
- 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
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
- Cannot create data stream.
- Only string and DateTime types are supported for…
- Returned string is too long for the buffer provided.
- SR.UnableToCreateStream
- ' ' cannot contain the path delimiter: ' '.
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)