dotnet/wpf · error · ArgumentException
SR.ParserWriterUnknownOrigin
Error message
SR.ParserWriterUnknownOrigin
What it means
XamlStream's WriterSeek validates the SeekOrigin value; any value other than Begin, Current, or End reaches the default branch and throws ArgumentException(SR.ParserWriterUnknownOrigin). This indicates an invalid SeekOrigin argument.
Solutions
- Pass a defined SeekOrigin value: SeekOrigin.Begin, SeekOrigin.Current, or SeekOrigin.End.
- Validate any externally supplied origin integer against Enum.IsDefined(typeof(SeekOrigin), value) before casting.
- Fix the caller that computes the origin value.
Example fix
// before
stream.Seek(offset, (SeekOrigin)originInt); // originInt = 9
// after
if (!Enum.IsDefined(typeof(SeekOrigin), originInt)) throw new ArgumentException("bad origin");
stream.Seek(offset, (SeekOrigin)originInt); Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(SeekOrigin), origin)) throw new ArgumentException(nameof(origin));
Type guard
bool validOrigin = origin is SeekOrigin.Begin or SeekOrigin.Current or SeekOrigin.End;
Try / catch
try { stream.Seek(offset, origin); }
catch (ArgumentException ex) when (ex.Message.Contains("origin")) { /* fix origin value */ } Prevention
- Always pass SeekOrigin enum members, never raw ints.
- Validate externally sourced origin values with Enum.IsDefined.
- Enable checked enum conversions in interop boundaries.
When it happens
Trigger: Calling Seek(offset, (SeekOrigin)someInt) on the XamlStream write side with an int that is not a defined SeekOrigin member (e.g. 3 or a negative/cast value).
Common situations: Origin value loaded from config/data or computed by cast instead of using SeekOrigin enum members; corrupted interop code passing a bad enum value.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ArgumentOutOfRangeException(nameof(offset))
- SR.ParserWriterNoSeekEnd
- Stream does not support Position setter
- Stream does not support Read
- can’t seek on baseStream
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/012699819ceff2de.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlStream.cs:155
/// Seek past the writeLength.
/// </summary>
/// <param name="offset">seek offset</param>
/// <param name="loc">specifies how to interpret the seeek offset</param>
/// <returns></returns>
internal long WriterSeek(long offset, SeekOrigin loc)
{
switch(loc)
{
case SeekOrigin.Begin:
WritePosition = (int) offset;
break;
case SeekOrigin.Current:
WritePosition = (int) (WritePosition + offset);
break;
case SeekOrigin.End:
throw new NotSupportedException(SR.ParserWriterNoSeekEnd);
default:
throw new ArgumentException(SR.ParserWriterUnknownOrigin);
}
if( (!( WritePosition <= WriteLength ))
||
(!( WritePosition >= ReadLength )) )
{
throw new ArgumentOutOfRangeException( nameof(offset));
}
return WritePosition;
}
/// <summary>
/// Called by the Writer to indicate its okay for the reader to see
/// the file up to and including the position. Once the Writer calls
/// this it cannot go back and change the content.
/// </summary>View on GitHub (pinned to 81131a70a4)