{"record":{"id":"1ad5a7940c0758ed","repo":"dotnet/maui","slug":"not-a-valid-type-of-bindingmode-property-return","errorCode":null,"errorMessage":"Not a valid type of BindingMode. Property: {returnType} {declaringType.Name}.{propertyName}. Default binding mode: {defaultBindingMode}","messagePattern":"Not a valid type of BindingMode\\. Property: (.+?) (.+?)\\.(.+?)\\. Default binding mode: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindableProperty.cs","lineNumber":203,"sourceCode":"\t\tprivate static int _nextInternalId = int.MinValue;\n\t\tinternal readonly int InternalId;\n\n\t\tBindableProperty(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay,\n\t\t\t\t\t\t\t\t ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null,\n\t\t\t\t\t\t\t\t CoerceValueDelegate coerceValue = null, BindablePropertyBindingChanging bindingChanging = null, bool isReadOnly = false, CreateDefaultValueDelegate defaultValueCreator = null)\n\t\t{\n\t\t\tif (propertyName == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(propertyName));\n\t\t\tif (returnType is null)\n\t\t\t\tthrow new ArgumentNullException(nameof(returnType));\n\t\t\tif (declaringType is null)\n\t\t\t\tthrow new ArgumentNullException(nameof(declaringType));\n\t\t\t\n\t\t\tInternalId = Interlocked.Increment(ref _nextInternalId);\n\n\t\t\t// don't use Enum.IsDefined as its redonkulously expensive for what it does\n\t\t\tif (defaultBindingMode != BindingMode.Default && defaultBindingMode != BindingMode.OneWay && defaultBindingMode != BindingMode.OneWayToSource && defaultBindingMode != BindingMode.TwoWay && defaultBindingMode != BindingMode.OneTime)\n\t\t\t\tthrow new ArgumentException($\"Not a valid type of BindingMode. Property: {returnType} {declaringType.Name}.{propertyName}. Default binding mode: {defaultBindingMode}\", nameof(defaultBindingMode));\n\n\t\t\tif (defaultValue == null && Nullable.GetUnderlyingType(returnType) == null && returnType.IsValueType)\n\t\t\t\tdefaultValue = Activator.CreateInstance(returnType);\n\n\t\t\tif (defaultValue != null && !returnType.IsInstanceOfType(defaultValue))\n\t\t\t\tthrow new ArgumentException($\"Default value did not match return type. Property: {returnType} {declaringType.Name}.{propertyName} Default value type: {defaultValue.GetType().Name}, \", nameof(defaultValue));\n\n\t\t\tif (defaultBindingMode == BindingMode.Default)\n\t\t\t\tdefaultBindingMode = BindingMode.OneWay;\n\n\t\t\tPropertyName = propertyName;\n\t\t\tReturnType = returnType;\n\t\t\tDeclaringType = declaringType;\n\t\t\tDefaultValue = defaultValue;\n\t\t\tDefaultBindingMode = defaultBindingMode;\n\t\t\tPropertyChanged = propertyChanged;\n\t\t\tPropertyChanging = propertyChanging;\n\t\t\tValidateValue = validateValue;","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindableProperty.cs#L185-L221","documentation":"ArgumentException thrown by the BindableProperty constructor when defaultBindingMode is not one of the defined BindingMode values (Default, OneWay, OneWayToSource, TwoWay, OneTime). The code deliberately avoids Enum.IsDefined for performance and instead whitelists the five valid modes; anything else (including a raw cast of an undefined int) is rejected, naming the offending property and mode.","triggerScenarios":"Calling BindableProperty.Create(..., mode: (BindingMode)99); casting an arbitrary integer to BindingMode; a stale enum value removed in a newer MAUI version being referenced by a compiled binary.","commonSituations":"Binary deserialization or reflection that assigns an out-of-range int to a BindingMode field; referencing an old assembly compiled against a previous enum definition; hand-rolled code-generation emitting numeric mode literals.","solutions":["Use a named BindingMode value (BindingMode.TwoWay, OneWay, OneWayToSource, OneTime, or Default).","If the mode comes from data, validate it against the five known values before passing it in.","Recompile any binary that was built against an older MAUI enum surface."],"exampleFix":"// before\nvar mode = (BindingMode)userInput; // userInput could be out of range\nvar bp = BindableProperty.Create(nameof(X), typeof(int), typeof(V), 0, mode);\n\n// after\nvar valid = mode is BindingMode.Default or BindingMode.OneWay or BindingMode.OneWayToSource\n            or BindingMode.TwoWay or BindingMode.OneTime;\nif (!valid) throw new ArgumentOutOfRangeException(nameof(userInput));","handlingStrategy":"validation","validationCode":"static bool IsValidMode(BindingMode m) =>\n    m is BindingMode.Default or BindingMode.OneWay or BindingMode.OneWayToSource\n      or BindingMode.TwoWay or BindingMode.OneTime;\n\nif (!IsValidMode(mode)) throw new ArgumentOutOfRangeException(nameof(mode));","typeGuard":"static bool IsValidMode(BindingMode m) =>\n    m is BindingMode.Default or BindingMode.OneWay or BindingMode.OneWayToSource\n      or BindingMode.TwoWay or BindingMode.OneTime;","tryCatchPattern":null,"preventionTips":["Never cast arbitrary ints to BindingMode.","Recompile binaries when the MAUI enum surface changes."],"tags":["maui","bindableproperty","argument-validation","enum","binding-mode"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}