dotnet/aspnetcore · error · InvalidOperationException
The type '{0}' does not have an associated TypeConverter tha
Error message
The type '{0}' does not have an associated TypeConverter that supports conversion from a string. Apply 'TypeConverterAttribute' to the type to register a converter. What it means
Thrown by BindConverter's ParserDelegateCache.MakeTypeConverterConverter when a type used in @bind has no TypeConverter capable of converting from a string. When the user edits an input, Blazor parses the DOM string back to the bound property's type; for non-primitive types it relies on TypeDescriptor.GetConverter, and if the converter cannot convert from string this InvalidOperationException is thrown. Apply [TypeConverter] with a converter supporting ConvertFrom(typeof(string)).
Source
Thrown at src/Components/Components/src/BindConverter.cs:2063
if (!elementParser(initialArray.GetValue(i), culture, out convertedArray[i]!))
{
value = default;
return false;
}
}
value = convertedArray;
return true;
}
}
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "We expect unknown underlying types are configured by application code to be retained.")]
private static BindParser<T> MakeTypeConverterConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>()
{
var typeConverter = TypeDescriptor.GetConverter(typeof(T));
if (typeConverter == null || !typeConverter.CanConvertFrom(typeof(string)))
{
throw new InvalidOperationException(
$"The type '{typeof(T).FullName}' does not have an associated {typeof(TypeConverter).Name} that supports " +
$"conversion from a string. " +
$"Apply '{typeof(TypeConverterAttribute).Name}' to the type to register a converter.");
}
return ConvertWithTypeConverter;
bool ConvertWithTypeConverter(object? obj, CultureInfo? culture, out T value)
{
// We intentionally close-over the TypeConverter to cache it. The TypeDescriptor infrastructure is slow.
if (obj == null)
{
value = default!;
return true;
}
var converted = typeConverter.ConvertFrom(context: null, culture ?? CultureInfo.CurrentCulture, obj);
if (converted == null)
{View on GitHub (pinned to 294cab2f9b)
Solutions
- Create a TypeConverter subclass overriding CanConvertFrom(typeof(string)) and ConvertFrom.
- Apply [TypeConverter(typeof(YourConverter))] to your custom type.
- Alternatively, bind a string property and parse manually, or use a built-in type.
Example fix
// before — binding a custom type throws on parse
public struct Money { public decimal Amount; public string Currency; }
// after
[TypeConverter(typeof(MoneyConverter))]
public struct Money { public decimal Amount; public string Currency; }
public class MoneyConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext c, Type t)
=> t == typeof(string) || base.CanConvertFrom(c, t);
public override object ConvertFrom(ITypeDescriptorContext c, CultureInfo ci, object v)
=> v is string s ? new Money { Amount = decimal.Parse(s, ci) } : base.ConvertFrom(c, ci, v);
} Defensive patterns
Strategy: type-guard
Validate before calling
var converter = TypeDescriptor.GetConverter(typeof(T));
if (converter is null || !converter.CanConvertFrom(typeof(string)))
throw new InvalidOperationException($"{typeof(T)} has no string-parsing TypeConverter."); Type guard
static bool CanParseFromString<T>()
{
var converter = TypeDescriptor.GetConverter(typeof(T));
return converter is not null && converter.CanConvertFrom(typeof(string));
} Prevention
- Implement both CanConvertFrom/ConvertFrom and CanConvertTo/ConvertTo for round-trippable custom types.
- Test TypeConverter parsing with edge-case strings (empty, culture-specific formats).
When it happens
Trigger: Binding @bind to a property of a custom type without a registered TypeConverter that supports parsing strings, and the type is not among the built-in set (string, numeric, bool, DateTime, Guid, enums, arrays). The parser lookup happens at BindConverter.cs:2058-2089.
Common situations: Custom value type bound to an <input @bind=...>; binding to a record/struct used in forms; using a domain type that lacks a string round-trip converter.
Related errors
- The type '{0}' does not have an associated TypeConverter tha
- There is no file with ID ${fileId}. The file list may have c
- Invalid sequence number or identifier '${sequenceOrIdentifie
- The options parameter is required.
- The event '${eventName}' is already registered.
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/cd21203cb945d1c5.
Report an issue: GitHub.