reactiveui/refit · error · ArgumentException
[Url] parameter "{param.Name}" must be of type string or Sys
Error message
[Url] parameter "{param.Name}" must be of type string or System.Uri What it means
A [Url] parameter must be a string or a System.Uri, because Refit constructs the request Uri from that value directly. Any other type (int, object, custom struct) cannot be used as an absolute URI source and is rejected.
Source
Thrown at src/Refit.Reflection/RestMethodInfoInternal.ParameterBinding.cs:444
{
var urlIndex = -1;
for (var i = 0; i < parameterArray.Length; i++)
{
var param = parameterArray[i];
if (sets[i].Url is null)
{
continue;
}
if (urlIndex >= 0)
{
throw new ArgumentException("Only one parameter can be a [Url] parameter");
}
if (param.ParameterType != typeof(string) && param.ParameterType != typeof(Uri))
{
throw new ArgumentException(
$"[Url] parameter \"{param.Name}\" must be of type string or System.Uri");
}
urlIndex = i;
}
return urlIndex;
}
}
View on GitHub (pinned to b455f65ecc)
Solutions
- Change the [Url] parameter type to string or Uri.
- If the value is an identifier rather than a URL, remove [Url] and put it in the route template instead.
Example fix
// before
[Get("")] Task GetAsync([Url] int endpointId);
// after
[Get("")] Task GetAsync([Url] string url); Defensive patterns
Strategy: type-guard
Validate before calling
static void AssertUrlType(ParameterInfo p) {
var t = p.ParameterType;
if (p.GetCustomAttribute<UrlAttribute>() is not null && t != typeof(string) && t != typeof(Uri))
throw new InvalidOperationException("[Url] parameter must be string or Uri.");
} Type guard
static bool IsUrlParameterType<T>() => typeof(T) == typeof(string) || typeof(T) == typeof(Uri);
Prevention
- Declare [Url] parameters as string or Uri.
- Use the route template for non-URL identifiers.
When it happens
Trigger: A parameter carries [Url] but its declared type is neither string nor Uri (e.g. int, Guid, a custom type).
Common situations: Mistakenly applying [Url] to an id or identifier parameter; refactor that changed the parameter type but kept [Url].
Related errors
- HeaderCollection parameter of type {parameterArray[i].Parame
- A [Url] method must not also declare a path template; [Url]
- Only one parameter can be a [Url] parameter
- Method must be defined and have an HTTP Method attribute
- Only one parameter can be a HeaderCollection parameter
AI-assisted analysis of reactiveui/refit@b455f65ecc (2026-08-13).
Data as JSON: /api/errors/101a115872f5e6f9.
Report an issue: GitHub.