stride3d/stride · error · ArgumentException
Invalid half format.
Error message
Invalid half format.
What it means
Half2Converter.ConvertFrom parses a Half2 from a string of exactly two values separated by the culture's list separator. If the split does not produce exactly 2 items it throws ArgumentException('Invalid half format.').
Solutions
- Supply exactly two numeric values separated by the culture's list separator, e.g. '1.5, 2.5'
- Ensure the parsing culture matches the format of the string (CultureInfo.InvariantCulture vs current)
- Pre-split and validate the part count is 2 before calling the converter
- Catch ArgumentException and report the expected format to the user
Example fix
// before converter.ConvertFromString(null, culture, "1.5") // after converter.ConvertFromString(null, culture, "1.5, 2.5")
Defensive patterns
Strategy: validation
Validate before calling
var parts = s.Trim().Split(culture.TextInfo.ListSeparator[0]);
if (parts.Length != 2) throw new FormatException("Half2 needs exactly 2 values"); Try / catch
try { v = (Half2)converter.ConvertFrom(s); }
catch (ArgumentException) { /* prompt for 'x, y' format */ } Prevention
- Serialize with the same culture used for parsing
- Use invariant culture for storage formats
- Check component count before convert
When it happens
Trigger: Calling ConvertFrom/ConvertFromString with a string that has not exactly 2 separator-delimited parts, e.g. '1.5' (1 part), '1.5, 2.0, 3.0' (3 parts), or a value using the wrong list separator for the culture (e.g. ';' vs ',').
Common situations: Asset/scene files hand-edited with wrong component counts; culture mismatch where the invariant ',' list separator differs from the user's locale; trailing separators creating empty extra parts.
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
- Invalid half format.
- Invalid half format.
- Invalid half format.
- The string does not match the expected format.
- Can't cast from to (more components)
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/a311f8b35416ee44.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Design/TypeConverters/Half2Converter.cs:127
/// </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 != 2)
{
throw new ArgumentException("Invalid half format.");
}
Half x = (Half)converter.ConvertFromString(context, culture, stringArray[0])!;
Half y = (Half)converter.ConvertFromString(context, culture, stringArray[1])!;
return new Half2(x, y);
}
/// <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)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(destinationType);View on GitHub (pinned to 96fad776d2)