{"record":{"id":"6aee60db554a87eb","repo":"dotnet/maui","slug":"mode-is-not-a-valid-bindingmode","errorCode":null,"errorMessage":"mode is not a valid BindingMode","messagePattern":"mode is not a valid BindingMode","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindingBase.cs","lineNumber":41,"sourceCode":"\t\tobject _fallbackValue;\n\t\tWeakReference<Element> _relativeSourceTargetOverride;\n\n\t\tinternal BindingBase()\n\t\t{\n\t\t}\n\n\t\t/// <summary>Gets or sets the mode for this binding.</summary>\n\t\tpublic BindingMode Mode\n\t\t{\n\t\t\tget { return _mode; }\n\t\t\tset\n\t\t\t{\n\t\t\t\tif (value != BindingMode.Default\n\t\t\t\t\t&& value != BindingMode.OneWay\n\t\t\t\t\t&& value != BindingMode.OneWayToSource\n\t\t\t\t\t&& value != BindingMode.TwoWay\n\t\t\t\t\t&& value != BindingMode.OneTime)\n\t\t\t\t\tthrow new ArgumentException(\"mode is not a valid BindingMode\", \"mode\");\n\n\t\t\t\tThrowIfApplied();\n\n\t\t\t\t_mode = value;\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>Gets or sets the string format applied to the bound value.</summary>\n\t\t/// <value>A standard <see cref=\"string.Format(string,object)\" /> composite format string. For single-value bindings use one placeholder (e.g., <c>{0:C2}</c>).</value>\n\t\t/// <remarks>\n\t\t/// Used to format or composite the resulting bound value for display. Implementations follow standard <see cref=\"string.Format(string,object)\" /> semantics.\n\t\t/// </remarks>\n\t\tpublic string StringFormat\n\t\t{\n\t\t\tget { return _stringFormat; }\n\t\t\tset\n\t\t\t{\n\t\t\t\tThrowIfApplied();","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindingBase.cs#L23-L59","documentation":"Thrown by the Mode property setter on BindingBase when the supplied value is not one of the valid BindingMode enum members (Default, OneWay, OneWayToSource, TwoWay, OneTime). The setter explicitly rejects any other integer/enum value, including undefined enum casts.","triggerScenarios":"Assigning binding.Mode = (BindingMode)999 or any value outside the five defined members. Casting an arbitrary integer to BindingMode and passing it to a Binding. Setting Mode from deserialized/config data that permits out-of-range values.","commonSituations":"Deserializing a BindingMode from JSON/config where the numeric value is out of range. Reflection-based binding configuration that passes a raw enum value. Migrating from another framework whose binding direction enum has extra members that map to invalid MAUI values.","solutions":["Validate the BindingMode against Enum.IsDefined(typeof(BindingMode), value) before assigning.","Restrict the source of the value to a known set of constants or a dropdown of valid members.","Coerce out-of-range values to BindingMode.Default as a safe fallback before assignment."],"exampleFix":"// before\nbinding.Mode = (BindingMode)configInt;\n\n// after\nbinding.Mode = Enum.IsDefined(typeof(BindingMode), configInt)\n    ? (BindingMode)configInt\n    : BindingMode.Default;","handlingStrategy":"validation","validationCode":"static BindingMode SafeMode(BindingMode value) =>\n    Enum.IsDefined(typeof(BindingMode), value) ? value : BindingMode.Default;\n\nbinding.Mode = SafeMode(incoming);","typeGuard":"static bool IsValidBindingMode(BindingMode m) =>\n    m == BindingMode.Default || m == BindingMode.OneWay ||\n    m == BindingMode.OneWayToSource || m == BindingMode.TwoWay ||\n    m == BindingMode.OneTime;","tryCatchPattern":null,"preventionTips":["Always validate deserialized enum values with Enum.IsDefined.","Restrict binding-mode inputs to a known set of UI options.","Default unknown values to BindingMode.Default."],"tags":["maui","binding","validation","enum"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}