Servicestack.Text

 async Task<T> GetOrCreateCacheAsync<T>(string key, bool reload, Func<Task<T>> factory)
{
      var cacheKey = $"{cachePrefix}:{key}";
      if (reload)
          Redis.Remove(cacheKey);
      await using var redis = await ServiceStackProvider.GetRedisAsync();
      return await redis.GetOrCreateAsync(cacheKey, cacheExpiry, async () => await factory());
}

public async Task Action2(BI2Data item, bool reload = false)
{
    var yq = item.yq;
    var item1 = await GetOrCreateCacheAsync($"Action2:zyfws", reload, async () =>
    {
        var query_item1 = Db.From<V_JSC_ZYFWS_YTD>().Where(p => p.RIQI.DayEqual(_riqi) && (yq.IsNan() || p.YUANQUID == yq))
          .Select(x => new
          {
              LIUYUANRS = Sql.Sum(x.LIUYUANRS),
              LIUYUANRS = Sql.Sum(x.XITONGKFCW),
          });
        return await Db.SelectAsync<(LIUYUANRS,LIUYUANRS)>(query_item1); 
    });
    item.LIUYUANRS = item1.Sum(x => x.LIUYUANRS);
    item.LIUYUANRS = item1.Sum(x => x.LIUYUANRS);
}

when run Action2,
I checked and found that the value stored in Redis is [β€œ(0, 0)”] β€” this format cannot be parsed, resulting in the following exception:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

After then, I asked grok.

The exception you encountered (System.ArgumentOutOfRangeException) is almost certainly caused by a defect or inadequate boundary handling in ServiceStack.Text’s deserialization implementation for ValueTuple (i.e., value tuples such as (int, int)).

how to solve it? or the exception can gave us more message. then can found the error quickly.

Structs and Value Types are serialized differently, you need to use a class not a Tuple or Record.

You can also use record class, e.g:

public record class(int LIUYUANRS, int LIUYUANRS);
1 Like