{"record":{"id":"8cdcf1dbf24d6677","repo":"dotnet/wpf","slug":"sr-format-sr-invalidctorparameterunknownfigureunittype-type","errorCode":null,"errorMessage":"SR.Format(SR.InvalidCtorParameterUnknownFigureUnitType, \"type\")","messagePattern":"SR\\.Format\\(SR\\.InvalidCtorParameterUnknownFigureUnitType, \"type\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs","lineNumber":119,"sourceCode":"            if (double.IsNaN(value))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoNaN, \"value\"));\n            }\n            if (double.IsInfinity(value))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoInfinity, \"value\"));\n            }\n            if (value < 0.0)\n            {\n                throw new ArgumentOutOfRangeException(SR.Format(SR.InvalidCtorParameterNoNegative, \"value\"));\n            }\n            if (    type != FigureUnitType.Auto\n                &&  type != FigureUnitType.Pixel\n                &&  type != FigureUnitType.Column\n                &&  type != FigureUnitType.Content\n                &&  type != FigureUnitType.Page   )\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterUnknownFigureUnitType, \"type\"));\n            }\n            if (type is FigureUnitType.Content or FigureUnitType.Page)\n            {\n                ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 1.0);\n            }\n\n            if (type == FigureUnitType.Column)\n            {\n                ArgumentOutOfRangeException.ThrowIfGreaterThan(value, maxColumns);\n            }\n\n            if (type == FigureUnitType.Pixel)\n            {\n                ArgumentOutOfRangeException.ThrowIfGreaterThan(value, maxPixel);\n            }\n\n            _unitValue = (type == FigureUnitType.Auto) ? 0.0 : value;\n            _unitType = type;","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs#L101-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar unit = (FigureUnitType)rawInt;\nvar length = new FigureLength(value, unit); // throws on unknown unit\n\n// after\nvar unit = (FigureUnitType)rawInt;\nif (!Enum.IsDefined(typeof(FigureUnitType), unit))\n    unit = FigureUnitType.Pixel;\nvar length = new FigureLength(value, unit);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(FigureUnitType), type))\n    throw new ArgumentException($\"Unknown FigureUnitType: {type}\");","typeGuard":"bool IsDefinedUnitType(FigureUnitType t) =>\n    t is FigureUnitType.Auto or FigureUnitType.Pixel or FigureUnitType.Column\n        or FigureUnitType.Content or FigureUnitType.Page;","tryCatchPattern":"try { var len = new FigureLength(value, type); }\ncatch (ArgumentException) { /* default to FigureUnitType.Pixel */ }","preventionTips":["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."],"tags":["wpf","invalid-enum-value","constructor","validation"],"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-21T21:30:21.729Z"}