Calling a GET service with multiple ids fails

I have a strange issue calling a GET service with multiple ids (List).

For one service it works, but for another service ServiceStackText exception is thrown, and I cannot understand why.

This service works with multiple ids (423, 331):

https://localhost:7750/api/query/reference/counterparties?Ids=423%2C%20331

[Route("/api/query/reference/counterparties", "GET")]
public class QueryCounterparties : QueryDb<Counterparty>, IGet
{
    public List<int> Ids { get; set; } = null!;
}

This service fails with multiple ids (423, 331), but is working with single id (e.g. 423 or 331):

[Route("/api/report/counterparties", "GET")]
public class QueryCounterpartiesReport : IReturn<CrudResponse<CounterpartiesReport>>, IGet
{
	public List<int> CounterpartyIds { get; set; } = null!;
}

400 response:

{
  "result": null,
  "responseStatus": {
    "errorCode": "FormatException",
    "message": "Input string was not in a correct format.",
    "stackTrace": null,
    "errors": [],
    "meta": null
  }
}

Stacktrace:

System.FormatException: Input string was not in a correct format.
   at ServiceStack.Text.SignedInteger`1.ParseInt64(ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/DefaultMemory.cs:line 895
   at ServiceStack.Text.SignedInteger`1.ParseObject(ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/DefaultMemory.cs:line 800
   at ServiceStack.Text.Common.JsReader`1.<>c__DisplayClass4_0`1.<GetCoreParseStringSpanFn>b__3(ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/JsReader.cs:line 69
   at ServiceStack.Text.Jsv.JsvReader.<>c__DisplayClass2_0.<GetParseFn>b__0(String v) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Jsv/JsvReader.Generic.cs:line 18
   at ServiceStack.Text.TypeSerializer.DeserializeFromString(String value, Type type) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/TypeSerializer.cs:line 90
   at ServiceStack.AutoMappingUtils.ChangeTo(String strValue, Type type) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/AutoMappingUtils.cs:line 363
   at ServiceStack.TypedQuery`2.AppendUntypedQueries(SqlExpression`1 q, Dictionary`2 dynamicParams, String defaultTerm, IAutoQueryOptions options, Dictionary`2 aliases) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/AutoQueryFeature.cs:line 1534
   at ServiceStack.TypedQuery`2.AddToQuery(ISqlExpression query, IQueryDb dto, Dictionary`2 dynamicParams, IAutoQueryOptions options, IRequest req) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/AutoQueryFeature.cs:line 1355
   at ServiceStack.AutoQuery.CreateQuery[From](IQueryDb`1 dto, Dictionary`2 dynamicParams, IRequest req, IDbConnection db) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/AutoQueryFeature.cs:line 962
   at ServiceStack.AutoQueryExtensions.CreateQuery[From](IAutoQueryDb autoQuery, IQueryDb`1 model, IRequest request, IDbConnection db) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Server/AutoQueryFeature.cs:line 1720
   at ServiceInterface.ReportNs.BusinessNs.CounterpartiesReportService.GetCounterparties(List`1 counterpartyIds) in C:\Yoyo\InternalApp\Application\RPT\code\src\ServiceInterface\ReportNs\BusinessNs\CounterpartiesReportService.cs:line 66
   at ServiceInterface.ReportNs.BusinessNs.CounterpartiesReportService.Get(QueryCounterpartiesReport request) in C:\Yoyo\InternalApp\Application\RPT\code\src\ServiceInterface\ReportNs\BusinessNs\CounterpartiesReportService.cs:line 28

Any ideas?

Using v8.3.1 on windows with .Net 8

The 2nd API QueryCounterpartiesReport is not an AutoQuery API, but the StackTrace shows it still uses AutoQuery? It shouldn’t be using it.

Does the API still throw the same error if you return the Request DTO?

public object Any(QueryCounterpartiesReport request) => request;

The error is caused by the following code in the 2nd API:

    private List<Counterparty> GetCounterparties(List<int> counterpartyIds)
    {
        using var db = AutoQuery!.GetDb<Counterparty>(Request);

        var find = new QueryCounterparties { Ids = counterpartyIds };
        var q = AutoQuery.CreateQuery(find, Request, db);
        var result = AutoQuery.Execute(find, q, Request, db);
        return result.Results;
    }

Which works if the counterpartyIds list contains a single value.

You’re creating a custom AutoQuery implementation with a different Request DTO but are using Request params from the original request. Since the DTO is already populated, try passing in an empty dictionary for the Request Params, e.g:

var q = AutoQuery.CreateQuery(find, new(), Request, db);

That worked, thank you for your insight.

Although, I do not understand why.