dotnet/wpf · error · ArgumentException
SR.Format(SR.InvalidCtorParameterUnknownFigureUnitType…
Error message
SR.Format(SR.InvalidCtorParameterUnknownFigureUnitType, "type")
What it means
The FigureLength constructor rejects a FigureUnitType outside the known set {Auto, Pixel, Column, Content, Page}, throwing ArgumentException with InvalidCtorParameterUnknownFigureUnitType. The unit type enum received a value not defined by FigureUnitType.
Solutions
- Validate with Enum.IsDefined(typeof(FigureUnitType), type) before constructing.
- Use only named FigureUnitType constants; avoid raw casts from int.
- Fix the deserialization/config source producing the unknown value.
Example fix
// before
var unit = (FigureUnitType)rawInt;
var length = new FigureLength(value, unit); // throws on unknown unit
// after
var unit = (FigureUnitType)rawInt;
if (!Enum.IsDefined(typeof(FigureUnitType), unit))
unit = FigureUnitType.Pixel;
var length = new FigureLength(value, unit); Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(FigureUnitType), type))
throw new ArgumentException($"Unknown FigureUnitType: {type}"); Type guard
bool IsDefinedUnitType(FigureUnitType t) =>
t is FigureUnitType.Auto or FigureUnitType.Pixel or FigureUnitType.Column
or FigureUnitType.Content or FigureUnitType.Page; Try / catch
try { var len = new FigureLength(value, type); }
catch (ArgumentException) { /* default to FigureUnitType.Pixel */ } Prevention
- Avoid raw int-to-enum casts; use named FigureUnitType constants.
- Validate enum values from config/deserialization with Enum.IsDefined.
- Watch for version-skew when enum values are persisted.
When it happens
Trigger: Calling new FigureLength(value, type) with an out-of-range or undefined FigureUnitType — e.g. an unvalidated cast from int or deserialization of a bad enum value.
Common situations: Casting raw ints to FigureUnitType from configuration or interop; enum values persisted by an older/newer version; deserializing corrupt or hand-edited XAML/serialized state.
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
- SR.Format(SR.Enum_Invalid, "DesignerSerializationOptions")
- ArgumentNullException
- ArgumentNullException(nameof(assemblyNames))
- ArgumentNullException(nameof(contentType))
- ArgumentNullException(nameof(loaderType))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8cdcf1dbf24d6677.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs:119
if (double.IsNaN(value))
{
throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoNaN, "value"));
}
if (double.IsInfinity(value))
{
throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoInfinity, "value"));
}
if (value < 0.0)
{
throw new ArgumentOutOfRangeException(SR.Format(SR.InvalidCtorParameterNoNegative, "value"));
}
if ( type != FigureUnitType.Auto
&& type != FigureUnitType.Pixel
&& type != FigureUnitType.Column
&& type != FigureUnitType.Content
&& type != FigureUnitType.Page )
{
throw new ArgumentException(SR.Format(SR.InvalidCtorParameterUnknownFigureUnitType, "type"));
}
if (type is FigureUnitType.Content or FigureUnitType.Page)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 1.0);
}
if (type == FigureUnitType.Column)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, maxColumns);
}
if (type == FigureUnitType.Pixel)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, maxPixel);
}
_unitValue = (type == FigureUnitType.Auto) ? 0.0 : value;
_unitType = type;View on GitHub (pinned to 81131a70a4)