{"record":{"id":"15d1adc4d0111e77","repo":"stride3d/stride","slug":"the-string-does-not-match-the-expected-format","errorCode":null,"errorMessage":"The string does not match the expected format.","messagePattern":"The string does not match the expected format\\.","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/TypeConverters/BaseConverter.cs","lineNumber":123,"sourceCode":"    }\n\n    protected TResult? ConvertFromString<TResult, T>(ITypeDescriptorContext? context, CultureInfo? culture, string str) where TResult : new()\n    {\n        if (string.IsNullOrEmpty(str))\n            return default;\n\n        culture ??= CultureInfo.CurrentCulture;\n\n        var converter = TypeDescriptor.GetConverter(typeof(T));\n        var strings = str.Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries);\n\n        // Note: we explicitly box the struct so we can use reflection to set values.\n        object result = new TResult();\n        foreach (var comp in strings)\n        {\n            var split = comp.Split(':');\n            if (split.Length != 2)\n                throw new FormatException(\"The string does not match the expected format.\");\n            var property = Properties.Cast<FieldPropertyDescriptor>().First(x => x.Name == split[0]);\n            var compValue = converter.ConvertFromString(context, culture, split[1]);\n            property.FieldInfo.SetValue(result, compValue);\n        }\n        return (TResult)result;\n    }\n\n    /// <summary>\n    /// Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.\n    /// </summary>\n    /// <param name=\"context\">An <see cref=\"T:System.ComponentModel.ITypeDescriptorContext\"/> that provides a format context.</param>\n    /// <param name=\"sourceType\">A <see cref=\"T:System.Type\"/> that represents the type you want to convert from.</param>\n    /// <returns>\n    /// true if this converter can perform the conversion; otherwise, false.\n    /// </returns>\n    public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)\n    {\n        return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/TypeConverters/BaseConverter.cs#L105-L141","documentation":"BaseConverter.ConvertFromString parses components of the form 'Name:Value' by splitting each component on ':'. A component that does not yield exactly two parts is rejected with a FormatException. The library expects structured 'field:value' pairs for the target struct.","triggerScenarios":"Calling ConvertFromString (or a TypeConverter.ConvertFrom with a string) where a component lacks the ':' separator, e.g. 'X' instead of 'X:1.0', or a component containing multiple colons producing more than 2 parts.","commonSituations":"Hand-edited property strings in editors/configs; localized input where users omit the field name; nested values that themselves contain ':' (e.g. times or URLs) accidentally breaking the split.","solutions":["Ensure each component is exactly 'FieldName:Value' with one colon separator","Escape or avoid ':' inside values; pre-check input with a regex like ^[A-Za-z_][A-Za-z0-9_]*:[^:]+$ per component","Catch FormatException and surface a descriptive message to the user","Verify the value part parses via the inner converter before assignment"],"exampleFix":"// before\nConvertFromString(\"X1.0, Y2.0\")\n// after\nConvertFromString(\"X:1.0, Y:2.0\")","handlingStrategy":"validation","validationCode":"static readonly Regex Comp = new(\"^[^:]+:[^:]+$\");\nbool ok = input.Split(',').All(c => Comp.IsMatch(c.Trim()));","typeGuard":null,"tryCatchPattern":"try { value = converter.ConvertFromString(context, culture, s); }\ncatch (FormatException ex) { /* show expected 'Name:Value' format */ }","preventionTips":["Always emit 'Name:Value' pairs","Avoid ':' inside values","Validate with regex before conversion"],"tags":["typeconverter","format","parsing","csharp"],"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"}