Every other cached response request gets System.NullReferenceException

I have an issue I can’t repro on local dev. Using redis cached provider;

 public object Get(getTotalOrderCnt req)
    {
        var sess = GetSession();

        try
        {
            var expireInTimespan = new TimeSpan(0, 15, 0);

            var cacheKey = <dollarsign>"getTotalOrderCnt:{sess.UserAuthId}";
            return base.Request.ToOptimizedResultUsingCache(base.Cache, cacheKey, expireInTimespan, () =>
            {
                var rv = new getTotalOrderCntResponse();
                try
                {
//do something long running in database to populate rv
              return rv;

                }
                catch (Exception e)
                {
                    Log.Error("NONE", "Something bad happened inside getTotalOrderCnt ", e);
                    return rv;
                   
                }


            });

        }
        catch(Exception e)
        {
            Log.Error("NONE", "Something bad happened getTotalOrderCnt ", e);
            return e;
        }



    }

2018-09-29 16:25:07.966 [NONE]:ERROR:Unhandled Error in ServiceStack Service from /order/GetCntOnFileAllAccounts System.NullReferenceException: Object reference not set to an instance of an object.
at PublicAPI.AppHost.<>c__DisplayClass1_0.b__3(IRequest httpReq, IResponse res, Object responseDto) in D:\home\site\repository\src\PublicAPI\Startup.cs:line 198
at ServiceStack.ServiceStackHost.ApplyResponseFiltersSingleAsync(IRequest req, IResponse res, Object response)
at ServiceStack.ServiceStackHost.ApplyResponseFiltersAsync(IRequest req, IResponse res, Object response)
at ServiceStack.Host.Handlers.ServiceStackHandlerBase.HandleResponseNext(IRequest httpReq, IResponse httpRes, Object response)
at ServiceStack.Host.Handlers.ServiceStackHandlerBase.HandleResponse(IRequest httpReq, IResponse httpRes, Object response)
at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest req, IResponse httpRes, String operationName)

The StackTrace indicates the NRE is in your code.

There is nothing that’s not in a try/catch except var sess = GetSession() and var rv = new getTotalOrderCntResponse() which is an empty constructor.

the src\PublicAPI\Startup.cs:line 198 piece is an unhandled exception handler. if I remove that it occurs in ApplyResponseFiltersSingleAsync

It’s executing a custom Response Filter registered in your Startup, what’s the StackTrace that shows the NRE Originated from ApplyResponseFilters?

Ugh… ok I see it. return optimized result does something different with responseDTO, we need to handle our filter better (and… try/catch that kind of stuff…)

THANK YOU.