dotnet/wpf · error · ArgumentOutOfRangeException
Specified argument was out of range of valid values…
Error message
Specified argument was out of range of valid values. (Parameter 'value')
What it means
The PageTrueTypeFont mode setting setter validates the assigned value against PrintSchema.TrueTypeFontModeEnumMin..Max. Assigning an int outside the defined TrueTypeFontMode enum range throws ArgumentOutOfRangeException with parameter 'value'.
Solutions
- Ensure the assigned value is a valid TrueTypeFontMode enum member
- Validate raw ints from external sources against Enum.IsDefined before casting
- Catch ArgumentOutOfRangeException and fall back to DeviceFont or Automatic default
Example fix
// before
mode = (TrueTypeFontMode)rawInt;
ticket.PageTrueTypeFont.Mode = mode;
// after
if (Enum.IsDefined(typeof(TrueTypeFontMode), rawInt))
ticket.PageTrueTypeFont.Mode = (TrueTypeFontMode)rawInt; Defensive patterns
Strategy: validation
Validate before calling
bool IsValidTrueTypeFontMode(int v) => v >= PrintSchema.TrueTypeFontModeEnumMin && v <= PrintSchema.TrueTypeFontModeEnumMax;
Type guard
static bool IsDefinedTrueTypeFontMode(object v) => v is int i && i >= PrintSchema.TrueTypeFontModeEnumMin && i <= PrintSchema.TrueTypeFontModeEnumMax;
Try / catch
try { ticket.PageTrueTypeFont.Mode = (TrueTypeFontMode)value; }
catch (ArgumentOutOfRangeException) { ticket.PageTrueTypeFont.Mode = TrueTypeFontMode.Automatic; } Prevention
- Bind UI to enum values, not raw ints
- Validate values read from config/data stores
- Guard against schema drift between framework versions
When it happens
Trigger: Assigning printTicket.PageTrueTypeFont.Mode (or the underlying PageTrueTypeFontModeSetting.Value) with a raw int not in the TrueTypeFontMode enum, e.g. from persisted data or an unvalidated cast.
Common situations: Loading saved PrintTicket XML from a different runtime version; round-tripping enum values through string/int config stores.
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
- Specified argument was out of range of valid values…
- Specified argument was out of range of valid values…
- Specified argument was out of range of valid values…
- Specified argument was out of range of valid values…
- Specified argument was out of range of valid values…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/5c281db1c290a847.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/PrintConfig/PageTrueTypeFont.cs:254
/// </summary>
/// <remarks>
/// If the setting is not specified yet, getter will return 0.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">
/// The value to set is not one of the standard <see cref="TrueTypeFontMode"/>.
/// </exception>
public TrueTypeFontMode Value
{
get
{
return (TrueTypeFontMode)this[PrintSchemaTags.Framework.OptionNameProperty];
}
set
{
if (value < PrintSchema.TrueTypeFontModeEnumMin ||
value > PrintSchema.TrueTypeFontModeEnumMax)
{
throw new ArgumentOutOfRangeException(nameof(value));
}
this[PrintSchemaTags.Framework.OptionNameProperty] = (int)value;
}
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Converts the page TrueType font handling mode setting to human-readable string.
/// </summary>
/// <returns>A string that represents this page TrueType font handling mode setting.</returns>
public override string ToString()
{
return Value.ToString();
}View on GitHub (pinned to 81131a70a4)