{"record":{"id":"18e7a654f5fe195e","repo":"stride3d/stride","slug":"nameof-value-is-not-a-numeric-type","errorCode":null,"errorMessage":"{nameof(value)} is not a numeric type","messagePattern":"(.+?) is not a numeric type","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToBool.cs","lineNumber":28,"sourceCode":"    /// This converter will convert a numerical value to a boolean. The result will be <c>false</c> if the given value is equal to zero, <c>true</c> otherwise.\n    /// </summary>\n    /// <remarks>Supported types are: <see cref=\"SByte\"/>, <see cref=\"Int16\"/>, <see cref=\"Int32\"/>, <see cref=\"Int64\"/>, <see cref=\"Byte\"/>, <see cref=\"UInt16\"/>, <see cref=\"UInt32\"/>, <see cref=\"UInt64\"/></remarks>\n    public class NumericToBool : OneWayValueConverter<NumericToBool>\n    {\n        /// <inheritdoc/>\n        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)\n        {\n            bool result;\n            if (value is sbyte) result = (sbyte)value != 0;\n            else if (value is short) result = (short)value != 0;\n            else if (value is int) result = (int)value != 0;\n            else if (value is long) result = (long)value != 0;\n            else if (value is byte) result = (byte)value != 0;\n            else if (value is ushort) result = (ushort)value != 0;\n            else if (value is uint) result = (uint)value != 0;\n            else if (value is ulong) result = (ulong)value != 0;\n            else\n                throw new ArgumentException($\"{nameof(value)} is not a numeric type\");\n            return result.Box();\n        }\n    }\n}\n","sourceCodeStart":10,"sourceCodeEnd":33,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToBool.cs#L10-L33","documentation":"NumericToBool converts a numeric value to a bool (true when non-zero, per its parameter logic). It explicitly pattern-matches the supported numeric types (int, long, byte, ushort, uint, ulong, etc.) and throws this ArgumentException when the incoming value matches none of them. It deliberately does not attempt arbitrary conversions, so non-numeric objects like strings, doubles outside its handled set, or control objects fail fast.","triggerScenarios":"Binding a non-numeric value (string, enum, object, double if not in the handled list) into a Binding whose Converter is NumericToBool, or calling Convert directly with such a value.","commonSituations":"Binding a string property from a TextBox directly through the converter; after a model refactor a numeric property became a string or nullable type not matched; passing an enum value expecting truthiness conversion.","solutions":["Bind a property that is one of the supported numeric types (int, long, byte, ushort, uint, ulong, etc.)","Place a prior converter (e.g. string-to-number) or use StringFormat/parsing in the view model before this converter","Check which types your Stride version's NumericToBool handles and align the bound type","Convert the value to a supported numeric type in the view model"],"exampleFix":"// before\npublic string Count { get; set; } // bound through NumericToBool\n// after\npublic int Count { get; set; } // supported numeric type","handlingStrategy":"type-guard","validationCode":"bool IsSupportedNumeric(object v) =>\n    v is sbyte || v is byte || v is short || v is ushort || v is int || v is uint || v is long || v is ulong;","typeGuard":"bool IsNumericForNumericToBool(object v) =>\n    v is sbyte || v is byte || v is short || v is ushort || v is int || v is uint || v is long || v is ulong;","tryCatchPattern":"try\n{\n    return converter.Convert(value, typeof(bool), parameter, culture);\n}\ncatch (ArgumentException)\n{\n    return false.Box(); // or a safe default\n}","preventionTips":["Bind only typed numeric properties (int, long, byte, ushort, uint, ulong) to this converter","Never bind string properties directly; parse in the view model first","Check the handled type list in your Stride version before relying on exotic numeric types","Add unit tests that call Convert with the exact types your bindings produce"],"tags":["wpf","valueconverter","numeric","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}