{"record":{"id":"4da1dcb0b25f6824","repo":"dotnet/wpf","slug":"sr-textrange-invalidparametervalue","errorCode":null,"errorMessage":"SR.TextRange_InvalidParameterValue","messagePattern":"SR\\.TextRange_InvalidParameterValue","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRange.cs","lineNumber":811,"sourceCode":"            }\n\n            // Check if the value is appropriate for the property\n            if (!formattingProperty.IsValidValue(value) &&\n                !(formattingProperty.PropertyType == typeof(Thickness) && (value is Thickness)))\n            {\n                // We exclude checking thcickness values because we have special treatment for negative values\n                // in TextRangeEdit.SetParagraphProperty - negative values mean: \"leave the value as is\".\n                throw new ArgumentException(SR.Format(SR.TextEditorTypeOfParameterIsNotAppropriateForFormattingProperty, value == null ? \"null\" : value.GetType().Name, formattingProperty.Name), nameof(value));\n            }\n\n            // Check propertyValueAction validity\n            if (propertyValueAction != PropertyValueAction.SetValue &&\n                propertyValueAction != PropertyValueAction.IncreaseByAbsoluteValue &&\n                propertyValueAction != PropertyValueAction.DecreaseByAbsoluteValue &&\n                propertyValueAction != PropertyValueAction.IncreaseByPercentageValue &&\n                propertyValueAction != PropertyValueAction.DecreaseByPercentageValue)\n            {\n                throw new ArgumentException(SR.TextRange_InvalidParameterValue, nameof(propertyValueAction));\n            }\n            // Check if propertyValueAction is applicable to this property\n            if (propertyValueAction != PropertyValueAction.SetValue &&\n                !TextSchema.IsPropertyIncremental(formattingProperty))\n            {\n                throw new ArgumentException(SR.Format(SR.TextRange_PropertyCannotBeIncrementedOrDecremented, formattingProperty.Name), nameof(propertyValueAction));\n            }\n\n            ApplyPropertyToTextVirtual(formattingProperty, value, applyToParagraphs, propertyValueAction);\n        }\n\n        /// <summary>\n        /// Removes all Inline formatting properties from this range.\n        /// Affects only Inline elements: splits the on range borders\n        /// and deletes all Inlines inside the range.\n        /// Properties set on Paragraphs and other enclosing Block elements\n        /// remain intact.\n        /// </summary>","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRange.cs#L793-L829","documentation":"TextRange.ApplyPropertyValue throws ArgumentException when the propertyValueAction parameter is not one of the five recognized PropertyValueAction values (SetValue, IncreaseByAbsoluteValue, DecreaseByAbsoluteValue, IncreaseByPercentageValue, DecreaseByPercentageValue). The library validates the action enum explicitly to prevent undefined behavior in property application. This is a caller-supplied parameter validation guard.","triggerScenarios":"Calling TextRange.ApplyPropertyValue (or TextSelection.ApplyPropertyValue overloads that accept a PropertyValueAction) with an out-of-range cast value like (PropertyValueAction)99, or a default-initialized struct that was never assigned a valid enum member.","commonSituations":"Reflection-based formatting code casting ints to PropertyValueAction; deserialized or persisted enum values from older WPF versions; copy-pasted code inventing new action names.","solutions":["Use only the defined PropertyValueAction members; for plain assignment use PropertyValueAction.SetValue","Check Enum.IsDefined(typeof(PropertyValueAction), action) before calling ApplyPropertyValue","If intending to increment/decrement, confirm the property supports it (see TextSchema.IsPropertyIncremental) and use the Increase/Decrease actions"],"exampleFix":"// before\nrange.ApplyPropertyValue(FontSizeProperty, 20.0, (PropertyValueAction)7);\n// after\nrange.ApplyPropertyValue(FontSizeProperty, 20.0, PropertyValueAction.SetValue);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(PropertyValueAction), action)) throw new ArgumentOutOfRangeException(nameof(action));","typeGuard":"bool IsValidPropertyValueAction(PropertyValueAction a) => a is PropertyValueAction.SetValue or PropertyValueAction.IncreaseByAbsoluteValue or PropertyValueAction.DecreaseByAbsoluteValue or PropertyValueAction.IncreaseByPercentageValue or PropertyValueAction.DecreaseByPercentageValue;","tryCatchPattern":"try { range.ApplyPropertyValue(prop, value, action); } catch (ArgumentException ex) { /* invalid PropertyValueAction */ }","preventionTips":["Always pass enum members by name, never cast ints","Default to PropertyValueAction.SetValue"],"tags":["wpf","argument-validation","enum"],"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"}