{"record":{"id":"bf8cbd548cecc6e7","repo":"dotnet/wpf","slug":"origin","errorCode":null,"errorMessage":"origin","messagePattern":"origin","errorType":"validation","errorClass":"System.ComponentModel.InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/ByteStream.cs","lineNumber":215,"sourceCode":"            {\n                case SeekOrigin.Begin:\n                    translatedSeekOrigin = NativeMethods.STREAM_SEEK_SET;\n                    if (0 > offset)\n                    {\n                        throw new ArgumentOutOfRangeException(nameof(offset),\n                                                              SR.SeekNegative);\n                    }\n                    break;\n\n                case SeekOrigin.Current:\n                    translatedSeekOrigin = NativeMethods.STREAM_SEEK_CUR;\n                    break;\n\n                case SeekOrigin.End:\n                    translatedSeekOrigin = NativeMethods.STREAM_SEEK_END;\n                    break;\n                default:\n                    throw new System.ComponentModel.InvalidEnumArgumentException(\"origin\",\n                                                                                 (int)origin,\n                                                                                 typeof(SeekOrigin));\n            }\n\n            _securitySuppressedIStream.Seek(offset, translatedSeekOrigin, out seekPos);\n\n            return seekPos;\n        }\n\n        /// <summary>\n        /// Sets the length of the current stream.\n        /// \n        /// Not Supported in this implementation.\n        /// </summary>\n        /// <param name=\"newLength\">New length</param>\n        public override void SetLength(long newLength)\n        {\n            throw new NotSupportedException(SR.SetLengthNotSupported);","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/ByteStream.cs#L197-L233","documentation":"ByteStream.Seek validates the origin parameter with a switch over SeekOrigin; any value outside Begin/Current/End falls into the default case and throws InvalidEnumArgumentException naming \"origin\". Note the message is just the parameter name because the exception carries the argument details.","triggerScenarios":"Calling Seek with an invalid cast value, e.g. (SeekOrigin)99, or passing a variable loaded from config/interop data that is not one of the three defined SeekOrigin values.","commonSituations":"Deserializing seek origin from persisted settings or P/Invoke-marshaled integers; third-party code passing int values into SeekOrigin casts.","solutions":["Pass only SeekOrigin.Begin, SeekOrigin.Current, or SeekOrigin.End literals.","Validate the integer before casting: if (Enum.IsDefined(typeof(SeekOrigin), value)).","Fix config/interop data to contain only 0, 1, or 2."],"exampleFix":"// before\nstream.Seek(off, (SeekOrigin)rawOrigin); // throws for rawOrigin not in {0,1,2}\n// after\nvar origin = Enum.IsDefined(typeof(SeekOrigin), rawOrigin) ? (SeekOrigin)rawOrigin : SeekOrigin.Begin;\nstream.Seek(off, origin);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(SeekOrigin), origin)) throw new InvalidEnumArgumentException(nameof(origin), (int)origin, typeof(SeekOrigin));","typeGuard":"bool IsValidSeekOrigin(int v) => v is >= 0 and <= 2;","tryCatchPattern":"try { stream.Seek(off, origin); }\ncatch (System.ComponentModel.InvalidEnumArgumentException) { origin = SeekOrigin.Begin; }","preventionTips":["Only pass literal SeekOrigin values","Validate persisted/marshaled ints with Enum.IsDefined before casting","Avoid storing SeekOrigin in loosely typed config"],"tags":["invalid-enum","argument","seek"],"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"}