reactiveui/refit · error · ArgumentException

Only one parameter can be a [Url] parameter

Error message

Only one parameter can be a [Url] parameter

What it means

Refit allows at most one [Url] parameter per method, since a single request can have only one absolute target URI. The loop tracks the first [Url] index and throws when it encounters a second [Url] parameter.

Source

Thrown at src/Refit.Reflection/RestMethodInfoInternal.ParameterBinding.cs:439

    /// <param name="sets">The classified attribute set for each parameter.</param>
    /// <returns>The index of the <c>[Url]</c> parameter, or a negative value when none is present.</returns>
    /// <exception cref="ArgumentException">More than one parameter carries <c>[Url]</c>, or the parameter is not a
    /// <see cref="string"/> or <see cref="Uri"/>.</exception>
    internal static int FindUrlParameter(ParameterInfo[] parameterArray, ParameterAttributeSet[] sets)
    {
        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

  1. Keep a single [Url] parameter and compose the full URI (base + path) before calling.
  2. If you need a configurable base, set it on the HttpClient/RefitSettings instead of a second [Url] param.

Example fix

// before
[Get("")] Task GetAsync([Url] string baseUrl, [Url] string path);

// after
[Get("")] Task GetAsync([Url] string fullUrl);
Defensive patterns

Strategy: validation

Validate before calling

static void AssertSingleUrl(MethodInfo m) {
    var count = m.GetParameters().Count(p => p.GetCustomAttribute<UrlAttribute>() is not null);
    if (count > 1) throw new InvalidOperationException("Multiple [Url] params on " + m.Name);
}

Prevention

When it happens

Trigger: Two parameters on the same method both carry the [Url] attribute.

Common situations: Copy-paste of an existing [Url] parameter; attempting to provide both a base URL and a resource URL as two [Url] params.

Related errors


AI-assisted analysis of reactiveui/refit@b455f65ecc (2026-08-13). Data as JSON: /api/errors/2766c0d3c5d044d7. Report an issue: GitHub.