SS Client "requires 2 values" error with AutoQuery

With the latest 4.5.13 from MyGet, I have found that when a DTO has a byte? property, the C# client will give an ArgumentException “requires 2 values” when using AutoQuery.

For example, Have a SQL table like this:

CREATE Table Customer
(
	CustomerID CHAR(20) NOT NULL,
	ChargeTo TINYINT NOT NULL
)

OrmLite’s T4 generates a DTO for the table and query like this:

public partial class Customer
{
	[Required]
	[PrimaryKey]
	public string CustomerID { get; set; }
	[Required]
	public byte ChargeTo { get; set; }
}

public partial class CustomerQuery : QueryDb<Customer>
{
	public string CustomerID { get; set; }
	public string CustomerIDStartsWith { get; set; }
	public string CustomerIDEndsWith { get; set; }
	public string CustomerIDContains { get; set; }
	public string CustomerIDLike { get; set; }
	public string[] CustomerIDBetween { get; set; }
	public string[] CustomerIDIn { get; set; }        

	public byte? ChargeTo { get; set; }

	public byte? ChargeToGreaterThanOrEqualTo { get; set; }
	public byte? ChargeToGreaterThan { get; set; }
	public byte? ChargeToLessThan { get; set; }
	public byte? ChargeToLessThanOrEqualTo { get; set; }
	public byte? ChargeToNotEqualTo { get; set; }
	public byte[] ChargeToBetween { get; set; }
	public byte[] ChargeToIn { get; set; }
}

In my Configure, I add the AutoQuery plugin and I choose to wire the route to the request when adding the route:

this.Plugins.Add(new AutoQueryFeature() { EnableAutoQueryViewer = true, MaxLimit = 20 });
this.Routes.Add(typeof(CustomerQuery), "/Queries/Customer", "GET", "Retrieves a list of customers.", "");

This all works, and visiting the /Queries/Customer in a browser correctly retrieves the results as expected.

However, using the ServiceStack client like so:

var client = new ServiceStack.JsonServiceClient("http://127.0.0.1:8088");
var CustomerQueryRequest = new CustomerQuery() { CustomerIDIn = new string[] { "1001", "1002" } };
var CustomerQueryResponse = client.Get(CustomerQueryRequest);

Will throw the exception. If I remove the ChargeTo column from the table or if I change the datatype from TINYINT to INT, regenerate the DTO and QueryDTO and update the ServiceStack reference in the client, then it works.

Please include the full StackTrace

    {400 ArgumentException
Code: ArgumentException, Message:  requires 2 values
Server StackTrace:
 [CustomerQuery: 03/07/2017 12:17:23 AM]:
[REQUEST: {CustomerIDBetween:[],CustomerIDIn:[1001,1002]}]
System.ArgumentException:  requires 2 values
   at ServiceStack.TypedQuery`2.AddCondition(SqlExpression`1 q, String defaultTerm, String quotedColumn, Object value, QueryDbFieldAttribute implicitQuery)
   at ServiceStack.TypedQuery`2.AppendUntypedQueries(SqlExpression`1 q, Dictionary`2 dynamicParams, String defaultTerm, IAutoQueryOptions options, Dictionary`2 aliases)
   at ServiceStack.TypedQuery`2.AddToQuery(ISqlExpression query, IQueryDb dto, Dictionary`2 dynamicParams, IAutoQueryOptions options)
   at ServiceStack.AutoQuery.CreateQuery[From](IQueryDb`1 dto, Dictionary`2 dynamicParams, IRequest req)
   at ServiceStack.AutoQueryServiceBase.Exec[From](IQueryDb`1 dto)
   at __AutoQueryServices.Any(CustomerQuery )
   at lambda_method(Closure , Object , Object )
   at ServiceStack.Host.ServiceRunner`1.Execute(IRequest req, Object instance, TRequest requestDto)

I wasn’t able to repro this issue in this commit, also note there’s build issues with:

var client = new ServiceStack.JsonServiceClient("http://127.0.0.1:8088");
var CustomerQueryRequest = new CustomerQuery() { CustomerIDIn = new string[] { "1001", "1002" } };
var CustomerQueryResponse = client.Get(CustomerQueryRequest);

Please put together a stand-alone project we can run locally (e.g. on GitHub) to see this issue.

Ok - thanks for looking into this. I have created 2 repo’s - one for the service, one for the client.

Repo for SelfHosted project
Repo for Client consuming above service

Thanks for the repro, this should now be resolved from this commit which is available from v4.5.13 that’s now available on MyGet.

1 Like

Great - thanks, mythz - tested and all working :smile:

1 Like