ThreeMammals/Ocelot · error · NotImplementedException
No conversion available for the type
Error message
No conversion available for the type: {targetType.Name} What it means
This is the explicit failure arm of ConvertToNumericType in DownstreamRouteExtensions, a helper that parses metadata string values into concrete numeric types (byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal, ...). The switch is an exhaustive allow-list; when a caller asks ConvertTo for a targetType that is none of the supported numeric types, no conversion arm matches and the method throws NotImplementedException, as documented by the <exception> tag on the method. The input at fault is the targetType argument — e.g. a bool, char, Guid, enum, or nullable/custom type passed through the metadata conversion path — not the string value itself. Because ConvertTo is used when reading route metadata into typed values, this error surfaces during request handling or startup whenever a metadata value's declared type is outside the supported numeric set.
Solutions
- Use only the supported numeric target types (byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal) when declaring metadata value types.
- Extend the switch expression in ConvertToNumericType with an arm for the missing targetType if the new type is legitimately needed.
- If non-numeric types are required, route them to a different conversion helper (e.g. bool/string parsing) instead of ConvertToNumericType.
- Validate the metadata configuration at startup so unsupported types are rejected before requests flow through the route.
- Catch NotImplementedException at the ConvertTo call site and fall back to returning the raw string value, logging the unsupported type.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at src/Metadata/DownstreamRouteExtensions.cs:150 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ThreeMammals/Ocelot@d1f22d9304 (2026-09-12).
Data as JSON: /api/errors/091fcb3711639ea3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Metadata/DownstreamRouteExtensions.cs:150
/// <param name="numberStyle">The current number style configuration.</param>
/// <returns>The parsed string as object of type targetType.</returns>
/// <exception cref="NotImplementedException">Exception thrown if the conversion for the type target type can't be found.</exception>
private static object ConvertToNumericType(string value, Type targetType, IFormatProvider provider, NumberStyles numberStyle)
{
return targetType switch
{
{ } t when t == typeof(byte) => byte.Parse(value, numberStyle, provider),
{ } t when t == typeof(sbyte) => sbyte.Parse(value, numberStyle, provider),
{ } t when t == typeof(short) => short.Parse(value, numberStyle, provider),
{ } t when t == typeof(ushort) => ushort.Parse(value, numberStyle, provider),
{ } t when t == typeof(int) => int.Parse(value, numberStyle, provider),
{ } t when t == typeof(uint) => uint.Parse(value, numberStyle, provider),
{ } t when t == typeof(long) => long.Parse(value, numberStyle, provider),
{ } t when t == typeof(ulong) => ulong.Parse(value, numberStyle, provider),
{ } t when t == typeof(float) => float.Parse(value, numberStyle, provider),
{ } t when t == typeof(double) => double.Parse(value, numberStyle, provider),
{ } t when t == typeof(decimal) => decimal.Parse(value, numberStyle, provider),
_ => throw new NotImplementedException($"No conversion available for the type: {targetType.Name}"),
};
}
}
View on GitHub (pinned to d1f22d9304)