{"record":{"id":"dad4907ab641026f","repo":"dotnet/wpf","slug":"1-is-not-a-valid-value-for-0-dad490","errorCode":null,"errorMessage":"'{1}' is not a valid value for '{0}'.","messagePattern":"'(.+?)' is not a valid value for '(.+?)'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/PrivateUnsafeNativeCompoundFileMethods.cs","lineNumber":178,"sourceCode":"                UInt64 libOffset,\n                UInt64 cb,\n                int dwLockType )\n            {\n                throw new NotSupportedException();\n            }\n\n\n            void UnsafeNativeILockBytes.Stat(\n                out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg,\n                int grfStatFlag )\n            {\n                CheckDisposed();\n\n                if ((grfStatFlag & ~(SafeNativeCompoundFileConstants.STATFLAG_NONAME | \n                                     SafeNativeCompoundFileConstants.STATFLAG_NOOPEN  )) != 0)\n                {\n                    // validate grfStatFlag's value\n                    throw new ArgumentException(SR.Format(SR.InvalidArgumentValue, \"grfStatFlag\", grfStatFlag.ToString(CultureInfo.InvariantCulture)));\n                }\n\n                System.Runtime.InteropServices.ComTypes.STATSTG returnValue = new System.Runtime.InteropServices.ComTypes.STATSTG\n                {\n                    grfLocksSupported = 0, // No lock supported\n\n                    cbSize = _baseStream.Length,\n                    type = SafeNativeCompoundFileConstants.STGTY_LOCKBYTES\n                };\n\n                pstatstg = returnValue;\n            }\n\n            private Stream _baseStream;\n        }\n\n        /////////////////////////////////////////////////////\n        // Security Suppressed Private Interfaces","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/PrivateUnsafeNativeCompoundFileMethods.cs#L160-L196","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlockBytes.Stat(0x10, out statstg); // unsupported flag\n// after\nconst int STATFLAG_NONAME = 1;\nlockBytes.Stat(STATFLAG_NONAME, out statstg);","handlingStrategy":"validation","validationCode":"const int STATFLAG_NONAME = 0x1, STATFLAG_NOOPEN = 0x2;\nif ((grfStatFlag & ~(STATFLAG_NONAME | STATFLAG_NOOPEN)) != 0)\n    throw new ArgumentException(nameof(grfStatFlag), \"only STATFLAG_NONAME/STATFLAG_NOOPEN are supported\");","typeGuard":null,"tryCatchPattern":"try { lockBytes.Stat(grfStatFlag, out statstg); }\ncatch (ArgumentException ex) { /* grfStatFlag contained unsupported bits */ }","preventionTips":["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"],"tags":["argument-validation","flag-value","com-interop"],"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"}