dotnet/wpf · error · ArgumentException
' ' is not a valid value for ' '.
Error message
'{1}' is not a valid value for '{0}'. What it means
The ILockBytes Stat implementation validates grfStatFlag, allowing only the STATFLAG_NONAME and STATFLAG_NOOPEN bits. Any other flag bit set causes ArgumentException (InvalidArgumentValue) because the wrapper does not support the full native STATSTG flag surface.
Solutions
- Pass only 0, STATFLAG_NONAME (1), STATFLAG_NOOPEN (2), or their combination.
- Mask the flag with (grfStatFlag & ~(STATFLAG_NONAME | STATFLAG_NOOPEN)) and reject before calling.
- Catch ArgumentException and inspect grfStatFlag.ToString() in the message to identify the bad value.
Example fix
// before lockBytes.Stat(0x10, out statstg); // unsupported flag // after const int STATFLAG_NONAME = 1; lockBytes.Stat(STATFLAG_NONAME, out statstg);
Defensive patterns
Strategy: validation
Validate before calling
const int STATFLAG_NONAME = 0x1, STATFLAG_NOOPEN = 0x2;
if ((grfStatFlag & ~(STATFLAG_NONAME | STATFLAG_NOOPEN)) != 0)
throw new ArgumentException(nameof(grfStatFlag), "only STATFLAG_NONAME/STATFLAG_NOOPEN are supported"); Try / catch
try { lockBytes.Stat(grfStatFlag, out statstg); }
catch (ArgumentException ex) { /* grfStatFlag contained unsupported bits */ } Prevention
- Pass only 0, STATFLAG_NONAME, STATFLAG_NOOPEN, or their combination
- Do not forward flag values from unrelated native APIs
- Define named constants instead of raw magic numbers
When it happens
Trigger: Calling IStream/ILockBytes Stat with grfStatFlag containing bits outside STATFLAG_NONAME (0x1) and STATFLAG_NOOPEN (0x2) — e.g. passing an undocumented value or a garbage/shifted flag.
Common situations: Porting native COM code that passes flags this managed wrapper doesn't support, or forwarding a value from another API whose flag enum has different bit meanings.
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
- 0x80040206
- 0x80040207
- ' ' is not a valid value for ' '.
- A read or write operation references a location outside the…
- ArgumentException(message, name)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/dad4907ab641026f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/PrivateUnsafeNativeCompoundFileMethods.cs:178
UInt64 libOffset,
UInt64 cb,
int dwLockType )
{
throw new NotSupportedException();
}
void UnsafeNativeILockBytes.Stat(
out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg,
int grfStatFlag )
{
CheckDisposed();
if ((grfStatFlag & ~(SafeNativeCompoundFileConstants.STATFLAG_NONAME |
SafeNativeCompoundFileConstants.STATFLAG_NOOPEN )) != 0)
{
// validate grfStatFlag's value
throw new ArgumentException(SR.Format(SR.InvalidArgumentValue, "grfStatFlag", grfStatFlag.ToString(CultureInfo.InvariantCulture)));
}
System.Runtime.InteropServices.ComTypes.STATSTG returnValue = new System.Runtime.InteropServices.ComTypes.STATSTG
{
grfLocksSupported = 0, // No lock supported
cbSize = _baseStream.Length,
type = SafeNativeCompoundFileConstants.STGTY_LOCKBYTES
};
pstatstg = returnValue;
}
private Stream _baseStream;
}
/////////////////////////////////////////////////////
// Security Suppressed Private InterfacesView on GitHub (pinned to 81131a70a4)