Issue with ToUrl(method) in TypedUrlResolver

I’m using a JsonServiceClient configured as following:

new JsonServiceClient(endPoint)
{
    OnAuthenticationRequired = OnAuthenticationRequired,
    TypedUrlResolver = TypedUrlResolver,
    UrlResolver = UrlResolver
};

Everything works fine if I remove the TypedUrlResolver. The delegate is built as follow:

private static string TypedUrlResolver(IServiceClientMeta client, string httpmethod, object requestdto)
{
    string url = requestdto.ToUrl(httpmethod);

    var matches = Regex.Match(url, @"(.*)\??(.*)?");

    string path = matches.Groups[1].Value;
    string query = matches.Groups[2].Value;

    var builder = new UriBuilder(client.BaseUri)
    {
        Path = string.Format("api{0}", path),
        Query = query
    };

    return builder.ToString();
}

The delegate crashes on ToUrl(method) with the following exception:

System.InvalidOperationException: There are no rest routes mapped for 'ServiceStack.Authenticate' type. (Note: The automatic route selection only works with [Route] attributes on the request DTO and not with routes registered in the IAppHost!)

The request is the Authenticate request that, in fact, does not have a [Route] attribute and gets resolved fine without the TypedUrlResolver. How can I solve the URL for those kind of DTO or just skip entirely and let the JsonServiceClient resolve the URL as if the TypedUrlResolver was missing?

Thanks.

Currently solved implementing the delegate as:

public static string TypedUrlResolver(IServiceClientMeta client, string httpmethod, object requestdto)
{
    string relativeUri;
    try
    {
        relativeUri = requestdto.ToUrl(httpmethod);
    }
    catch (InvalidOperationException)
    {
        // servicestack restituisce InvalidOperationException se si prova a fare una ToUrl()
        // per un DTO che non ha una route definita. Alcuni DTO però (come Authenticate) di fatto
        // non hanno una route definita in modo esplicito.
        return null;
    }

    var uri = new Uri(new Uri(client.BaseUri), relativeUri);

    var builder = new UriBuilder(client.BaseUri)
    {
        Path = Regex.Replace(uri.AbsolutePath, @"^(\/api)?([\/a-z0-9\-]*)", @"/api$2"),
        Query = uri.Query
    };

    return builder.ToString();
}

You can check if a Request DTO has a [Route] attribute with:

requestDto.GetType().HasAttribute<RouteAttribute>();