stride3d/stride · error · ArgumentException

Invalid half format.

Error message

Invalid half format.

What it means

Parse failure in Half4Converter.ConvertFrom: the string being converted to a Half4 does not match the expected numeric format (four comma/space-separated half values), so parsing was abandoned. The faulting input is the string passed via the value parameter to the type converter.

Solutions

  1. Pass exactly four values: '1.0, 0.0, 0.0, 1.0'
  2. Use the same culture for parse as for the original ToString
  3. Pre-split on the culture's list separator and assert length == 4
  4. Catch ArgumentException, show expected 'x, y, z, w' format

Example fix

// before
converter.ConvertFromString(null, culture, "1.0, 0.0, 0.0")
// after
converter.ConvertFromString(null, culture, "1.0, 0.0, 0.0, 1.0")
Defensive patterns

Strategy: validation

Validate before calling

var parts = s.Trim().Split(culture.TextInfo.ListSeparator[0]);
if (parts.Length != 4) throw new FormatException("Half4 needs exactly 4 values");

Try / catch

try { v = (Half4)converter.ConvertFrom(s); }
catch (ArgumentException) { /* prompt for 'x, y, z, w' format */ }

Prevention

When it happens

Trigger: ConvertFrom/ConvertFromString receiving a string that splits into != 4 parts — fewer (e.g. a 3-component vector), more (e.g. extra separators), or a culture whose list separator differs from the one in the string.

Common situations: Storing RGBA/quaternion data with wrong component count; locale mismatches between save and load; hand-edited YAML/asset files dropping or adding a component.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/d760310120d735ff. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Design/TypeConverters/Half4Converter.cs:131

    /// </summary>
    /// <param name = "context">A <see cref = "T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
    /// <param name = "culture">A <see cref = "T:System.Globalization.CultureInfo" />. If <c>null</c> is passed, the current culture is assumed.</param>
    /// <param name = "value">The <see cref = "T:System.Object" /> to convert.</param>
    /// <returns>An <see cref = "T:System.Object" /> that represents the converted value.</returns>
    public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
    {
        culture ??= CultureInfo.CurrentCulture;
        if (value is not string str)
        {
            return base.ConvertFrom(context, culture, value);
        }
        str = str.Trim();
        TypeConverter converter = TypeDescriptor.GetConverter(typeof(Half));
        char[] separator = [culture.TextInfo.ListSeparator[0]];
        string[] stringArray = str.Split(separator);
        if (stringArray.Length != 4)
        {
            throw new ArgumentException("Invalid half format.");
        }
        Half x = (Half)converter.ConvertFromString(context, culture, stringArray[0])!;
        Half y = (Half)converter.ConvertFromString(context, culture, stringArray[1])!;
        Half z = (Half)converter.ConvertFromString(context, culture, stringArray[2])!;
        Half w = (Half)converter.ConvertFromString(context, culture, stringArray[3])!;
        return new Half4(x, y, z, w);
    }

    /// <summary>
    ///   Converts the given value object to the specified type, using the specified context and culture information.
    /// </summary>
    /// <param name = "context">A <see cref = "T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
    /// <param name = "culture">A <see cref = "T:System.Globalization.CultureInfo" />. If <c>null</c> is passed, the current culture is assumed.</param>
    /// <param name = "value">The <see cref = "T:System.Object" /> to convert.</param>
    /// <param name = "destinationType">A <see cref = "T:System.Type" /> that represents the type you want to convert to.</param>
    /// <returns>An <see cref = "T:System.Object" /> that represents the converted value.</returns>
    public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
    {

View on GitHub (pinned to 96fad776d2)