{"record":{"id":"7f621a5bec35e468","repo":"dotnet/wpf","slug":"1-is-not-a-valid-value-for-0","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/NativeCompoundFileAPIs.cs","lineNumber":610,"sourceCode":"                    {\n                        MS.Win32.UnsafeNativeMethods.SafeReleaseComObject((object) _unsafeStream);\n                    }\n                }\n                finally\n                {\n                    _unsafeStream = null;\n                }\n            }\n\n            //\n            // IStream Implementation\n            //\n            void IStream.Read(Byte[] pv, int cb, out int pcbRead)\n            {\n\n                if (cb < 0)\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidArgumentValue, \"cb\", cb.ToString(CultureInfo.InvariantCulture)));\n                }\n\n                _unsafeStream.Read(pv, cb, out pcbRead);\n            }\n\n            void IStream.Write(Byte[] pv, int cb, out int pcbWritten)\n            {\n\n                if (cb < 0)\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidArgumentValue, \"cb\", cb.ToString(CultureInfo.InvariantCulture)));\n                }\n\n                _unsafeStream.Write(pv, cb, out pcbWritten);\n            }\n\n\n            // IStream portion","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/NativeCompoundFileAPIs.cs#L592-L628","documentation":"The internal IStream.Read implementation validates that the requested byte count is non-negative before delegating to the underlying unsafe stream. A negative cb yields ArgumentException with SR.InvalidArgumentValue formatting ('cb' is not a valid value).","triggerScenarios":"Calling IStream.Read (or code that funnels into it) with cb < 0.","commonSituations":"Incorrect buffer/length math (e.g. subtracting larger offsets), or marshaling bugs passing negative counts.","solutions":["Ensure the count passed to Read is >= 0, clamping if needed","Check upstream arithmetic that computes the read length","Catch ArgumentException around the Read call and log the offending cb value"],"exampleFix":"// before\nstream.Read(buffer, bytesRemaining);\n// after\nint cb = Math.Max(0, bytesRemaining);\nstream.Read(buffer, cb);","handlingStrategy":"validation","validationCode":"if (cb < 0) throw new ArgumentOutOfRangeException(nameof(cb));","typeGuard":null,"tryCatchPattern":"try { stream.Read(buffer, cb, out read); } catch (ArgumentException ex) when (ex.Message.Contains(\"cb\")) { /* clamp cb and retry */ }","preventionTips":["Clamp read lengths with Math.Max(0, n)","Check offset arithmetic feeding cb","Never use -1 as a byte-count sentinel"],"tags":["wpf","packaging","istream","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}