{"record":{"id":"79bafc500c64f71e","repo":"AvaloniaUI/Avalonia","slug":"invalid-bindingvaluetype","errorCode":null,"errorMessage":"Invalid BindingValueType.","messagePattern":"Invalid BindingValueType\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/BindingValue.cs","lineNumber":166,"sourceCode":"        /// appropriate.\n        /// </summary>\n        /// <returns>The untyped representation of the binding value.</returns>\n        public object? ToUntyped()\n        {\n            return Type switch\n            {\n                BindingValueType.UnsetValue => AvaloniaProperty.UnsetValue,\n                BindingValueType.DoNothing => BindingOperations.DoNothing,\n                BindingValueType.Value => _value,\n                BindingValueType.BindingError =>\n                    new BindingNotification(Error!, BindingErrorType.Error),\n                BindingValueType.BindingErrorWithFallback =>\n                    new BindingNotification(Error!, BindingErrorType.Error, Value),\n                BindingValueType.DataValidationError =>\n                    new BindingNotification(Error!, BindingErrorType.DataValidationError),\n                BindingValueType.DataValidationErrorWithFallback =>\n                    new BindingNotification(Error!, BindingErrorType.DataValidationError, Value),\n                _ => throw new NotSupportedException(\"Invalid BindingValueType.\"),\n            };\n        }\n\n        /// <summary>\n        /// Returns a new binding value with the specified value.\n        /// </summary>\n        /// <param name=\"value\">The new value.</param>\n        /// <returns>The new binding value.</returns>\n        /// <exception cref=\"InvalidOperationException\">\n        /// The binding type is <see cref=\"BindingValueType.UnsetValue\"/> or\n        /// <see cref=\"BindingValueType.DoNothing\"/>.\n        /// </exception>\n        public BindingValue<T> WithValue(T value)\n        {\n            if (Type == BindingValueType.DoNothing)\n            {\n                throw new InvalidOperationException(\"Cannot add value to DoNothing binding value.\");\n            }","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/BindingValue.cs#L148-L184","documentation":"Thrown as NotSupportedException by BindingValue<T>.ToObject() when the Type field does not match any known BindingValueType case in its switch expression (the default/_ arm). BindingValueType is a [Flags] enum; an unrecognized or corrupted flag combination that doesn't equal any named member triggers the default arm.","triggerScenarios":"BindingValue<T> is constructed directly (bypassing the static factory methods) with a Type value that is not one of UnsetValue, DoNothing, Value, BindingError, BindingErrorWithFallback, DataValidationError, DataValidationErrorWithFallback. Also theoretically reachable if reflection/binary deserialization produces an invalid enum.","commonSituations":"Internal/advanced code manually constructing BindingValue<T> with an invalid Type. Deserialization corruption. Unreleased enum member not handled by the switch. This is a defensive guard; normal factory APIs never produce this.","solutions":["Always construct BindingValue<T> via its static factory methods (e.g., BindingValue<T>.FromValue, FromError) rather than the constructor, so Type is always valid.","If you must construct directly, ensure Type is exactly one of the named BindingValueType members.","Validate the Type against known members before calling ToObject()."],"exampleFix":"// before\nvar bv = new BindingValue<T>((BindingValueType)999, value, null);\nvar o = bv.ToObject(); // throws\n// after\nvar bv = BindingValue<T>.FromValue(value); // factory sets a valid Type","handlingStrategy":"validation","validationCode":"var known = bv.Type is BindingValueType.UnsetValue or BindingValueType.DoNothing\n    or BindingValueType.Value or BindingValueType.BindingError\n    or BindingValueType.BindingErrorWithFallback\n    or BindingValueType.DataValidationError or BindingValueType.DataValidationErrorWithFallback;\nif (known) var o = bv.ToObject();","typeGuard":"static bool IsValidType(BindingValueType t) =>\n    t is BindingValueType.UnsetValue or BindingValueType.DoNothing or BindingValueType.Value\n    or BindingValueType.BindingError or BindingValueType.BindingErrorWithFallback\n    or BindingValueType.DataValidationError or BindingValueType.DataValidationErrorWithFallback;","tryCatchPattern":"try { var o = bv.ToObject(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Invalid BindingValueType\"))\n{ /* log:BindingValue constructed with invalid Type; use a factory method */ }","preventionTips":["Always build BindingValue<T> via static factory methods, never the constructor.","Validate Type against known members before ToObject().","Treat this exception as a defect indicator, not a runtime path."],"tags":["binding","bindingvalue","enum","internal"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}