{"record":{"id":"1b8aa2167150c6eb","repo":"dotnet/wpf","slug":"cannot-set-position-of-the-stream-to-a-negative-value","errorCode":null,"errorMessage":"Cannot set position of the stream to a negative value.","messagePattern":"Cannot set position of the stream to a negative value\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/UnsafeIndexingFilterStream.cs","lineNumber":240,"sourceCode":"            }\n        }\n\n        /// <summary>\n        /// Logical byte position in this stream\n        /// </summary>\n        public override long Position\n        {\n            get\n            {\n                ThrowIfStreamDisposed();\n                return Seek(0, SeekOrigin.Current);\n            }\n            set\n            {\n                ThrowIfStreamDisposed();\n\n                if (value < 0)\n                    throw new ArgumentException(SR.CannotSetNegativePosition);\n\n                Seek(value, SeekOrigin.Begin);\n            }\n        }\n\n        /// <summary>\n        /// Length.\n        /// </summary>\n        public override long Length\n        {\n            get\n            {\n                ThrowIfStreamDisposed();\n\n                // Retrieve stream stats. STATFLAG_NONAME means don't return the stream name.\n                System.Runtime.InteropServices.ComTypes.STATSTG statstg;\n                _oleStream.Stat(out statstg, NativeMethods.STATFLAG_NONAME);\n                return statstg.cbSize;","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/UnsafeIndexingFilterStream.cs#L222-L258","documentation":"ArgumentException thrown by the Position setter on UnsafeIndexingFilterStream when the caller assigns a negative value: the seek-based logical position cannot be moved before the beginning of the stream.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/UnsafeIndexingFilterStream.cs:240 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Clamp the requested position to >= 0 before assigning","Validate user-supplied offsets (e.g. from a parser or progress calculation) for negative values before seeking"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}