{"record":{"id":"cb5dd5003d9f3135","repo":"stride3d/stride","slug":"invalid-half-format-halfconverter","errorCode":null,"errorMessage":"Invalid half format.","messagePattern":"Invalid half format\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/TypeConverters/HalfConverter.cs","lineNumber":108,"sourceCode":"    /// Converts the given object to the type of this converter, using the specified context and culture information.\n    /// </summary>\n    /// <param name=\"context\">A <see cref=\"T:System.ComponentModel.ITypeDescriptorContext\" /> that provides a format context.</param>\n    /// <param name=\"culture\">A <see cref=\"T:System.Globalization.CultureInfo\" />. If <c>null</c> is passed, the current culture is assumed.</param>\n    /// <param name=\"value\">The <see cref=\"T:System.Object\" /> to convert.</param>\n    /// <returns>An <see cref=\"T:System.Object\" /> that represents the converted value.</returns>\n    public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)\n    {\n        culture ??= CultureInfo.CurrentCulture;\n        if (value is not string str)\n        {\n            return base.ConvertFrom(context, culture, value);\n        }\n        str = str.Trim();\n        char[] separator = [culture.TextInfo.ListSeparator[0]];\n        string[] stringArray = str.Split(separator);\n        if (stringArray.Length != 1)\n        {\n            throw new ArgumentException(\"Invalid half format.\");\n        }\n        float h = (float)TypeDescriptor.GetConverter(typeof(float)).ConvertFromString(context, culture, stringArray[0])!;\n        return new Half(h);\n    }\n\n    /// <summary>\n    /// Converts the given value object to the specified type, using the specified context and culture information.\n    /// </summary>\n    /// <param name=\"context\">A <see cref=\"T:System.ComponentModel.ITypeDescriptorContext\" /> that provides a format context.</param>\n    /// <param name=\"culture\">A <see cref=\"T:System.Globalization.CultureInfo\" />. If <c>null</c> is passed, the current culture is assumed.</param>\n    /// <param name=\"value\">The <see cref=\"T:System.Object\" /> to convert.</param>\n    /// <param name=\"destinationType\">A <see cref=\"T:System.Type\" /> that represents the type you want to convert to.</param>\n    /// <returns>An <see cref=\"T:System.Object\" /> that represents the converted value.</returns>\n    public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)\n    {\n#if NET6_0_OR_GREATER\n        ArgumentNullException.ThrowIfNull(destinationType);\n#else","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/TypeConverters/HalfConverter.cs#L90-L126","documentation":"HalfConverter.ConvertFrom parses a single Half value from a string; it requires the split on the culture list separator to yield exactly 1 item (i.e. no list separator present). Extra separators or grouped input throw ArgumentException('Invalid half format.').","triggerScenarios":"ConvertFrom/ConvertFromString called with a multi-component string like '1.0, 2.0' where a scalar Half is expected; or strings containing the culture's list separator anywhere, including trailing '1.0,'.","commonSituations":"Pasting a vector into a scalar Half field; regional list separators appearing inside the value; copy-paste whitespace/separator mistakes in editors.","solutions":["Pass a single numeric value with no list separator: '1.5'","Strip stray separators/whitespace before conversion","Validate the string is a plain float (float.TryParse with the target culture) before calling","Catch ArgumentException and coerce multi-value input by taking/averaging components deliberately"],"exampleFix":"// before\nconverter.ConvertFromString(null, culture, \"1.0, 2.0\")\n// after\nconverter.ConvertFromString(null, culture, \"1.0\")","handlingStrategy":"validation","validationCode":"if (!float.TryParse(s.Trim(), NumberStyles.Float, culture, out _))\n    throw new FormatException(\"Half expects a single numeric value\");","typeGuard":null,"tryCatchPattern":"try { h = (Half)converter.ConvertFrom(s); }\ncatch (ArgumentException) { /* coerce or reject multi-value input */ }","preventionTips":["Don't paste vectors into scalar fields","Trim and strip separators first","Use TryParse as a pre-check"],"tags":["typeconverter","parsing","half"],"backgroundTag":"invalid-argument-format","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}