{"record":{"id":"f6061064c27668b1","repo":"dotnet/wpf","slug":"seekorigin-value-is-not-valid","errorCode":null,"errorMessage":"SeekOrigin value is not valid.","messagePattern":"SeekOrigin value is not valid\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs","lineNumber":250,"sourceCode":"                            temp = offset;\n                            break;\n                        }\n\n                    case SeekOrigin.Current:\n                        {\n                            temp = _position + offset;\n                            break;\n                        }\n\n                    case SeekOrigin.End:\n                        {\n                            temp = Length + offset;\n                            break;\n                        }\n\n                    default:\n                        {\n                            throw new ArgumentOutOfRangeException(nameof(origin), SR.SeekOriginInvalid);\n                        }\n                }\n            }\n            if (temp < 0)\n            {\n                throw new ArgumentException(SR.SeekNegative);\n            }\n\n#if DEBUG\n            if (System.IO.Packaging.PackWebRequestFactory._traceSwitch.Enabled)\n                System.Diagnostics.Trace.TraceInformation(\"NetStream.Seek() pos:{0}\", temp);\n#endif\n            _position = temp;\n            return _position;\n        }\n\n\n        /// <summary>","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/NetStream.cs#L232-L268","documentation":"NetStream.Seek switches on the SeekOrigin parameter (Begin/Current/End); any value outside these three hits the default case and throws ArgumentOutOfRangeException. This library throws it because only the three standard origins are defined.","triggerScenarios":"Calling Seek(long offset, SeekOrigin origin) with an invalid (cast or uninitialized) origin value such as (SeekOrigin)3 or default(SeekOrigin) in non-zero-based code paths.","commonSituations":"Storing the origin in an int/byte field and casting it back after refactoring; passing a value read from configuration; enum extensions not supported by SeekOrigin (e.g. custom 'Start' origin).","solutions":["Pass only SeekOrigin.Begin, SeekOrigin.Current, or SeekOrigin.End","Validate the origin against Enum.IsDefined(typeof(SeekOrigin), value) before calling Seek","If a custom origin is needed, compute the absolute offset yourself and use SeekOrigin.Begin"],"exampleFix":"// before\nstream.Seek(delta, (SeekOrigin)myInt);\n// after\nvar origin = Enum.IsDefined(typeof(SeekOrigin), myInt) ? (SeekOrigin)myInt : SeekOrigin.Begin;\nstream.Seek(delta, origin);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(SeekOrigin), origin))\n    throw new ArgumentException($\"Invalid SeekOrigin: {origin}\");\nstream.Seek(offset, origin);","typeGuard":"static bool IsDefinedSeekOrigin(SeekOrigin o) => o is SeekOrigin.Begin or SeekOrigin.Current or SeekOrigin.End;","tryCatchPattern":"try { stream.Seek(offset, origin); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"origin\") { origin = SeekOrigin.Begin; stream.Seek(offset, origin); }","preventionTips":["Never cast ints/bytes to SeekOrigin without Enum.IsDefined validation","Only reference SeekOrigin's three named members","Translate custom origin semantics to absolute offsets before seeking"],"tags":["packaging","stream","seek","argument-out-of-range"],"backgroundTag":"invalid-enum-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"}