How to debug cachedresponse 500 error

i have an endpoint witha
[CacheResponse(Duration = 3600)] set that works and returns the correct response when requested second time is returning a 500 server error how can I test or debug this?

Do you have DebugMode enabled?

If so the Exception info should be in the HTTP Response.

You should also be able to catch and inspect the Exception by overriding OnExceptionTypeFilter in your AppHost.

yes it is set to true but the same result 500 error response no exception raised

Try registering an UncaughtExceptionHandler.

I have added those to configure but cannot see or get access to the exception

i was able to get the error here is the stack trace

at ServiceStack.CacheResponseExtensions.d__1.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\CacheResponseAttribute.cs:line 202
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.CacheResponseAttribute.d__33.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\CacheResponseAttribute.cs:line 132
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at ServiceStack.ServiceStackHost.d__386.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\ServiceStackHost.Runtime.cs:line 227
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.ServiceStackHost.d__385.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\ServiceStackHost.Runtime.cs:line 145
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at ServiceStack.Host.RestHandler.d__14.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\RestHandler.cs:line 92

Can you right-click the CacheResponse attribute and debug the implementation to find out what the issue is. Also what’s the actual Exception Message & Type?

the exception caught in serviceExceptionHandlers. is
Object reference not set to an instance of an object.
source:ServiceStack
trace is:
at ServiceStack.CacheResponseExtensions.d__1.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\CacheResponseAttribute.cs:line 202
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ServiceStack.CacheResponseAttribute.d__33.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\CacheResponseAttribute.cs:line 132
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at ServiceStack.Host.ServiceRunner`1.d__15.MoveNext() in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Host\ServiceRunner.cs:line 130

Can you debug into the class (i.e. by right-clicking the CacheResponse attribute) to find out what’s null?

no, i am not able to debug the class unfortunately getting the symbol has no implementation when I attemptto go to implementation

we endedup up reverting back to servicestack 5.8 which fixed the problem for us

@bobk are you using an IRedisClientsManagerAsync in your AppHost?

I’ve pushed a fix to the latest v5.11.1 which is now available on MyGet. Change was made in this commit to fix a possible null reference exception that could be the cause of the problem you are seeing. If you could upgrade and let us know if you are still getting the same error for the CacheResponse attribute when you upgrade your project. Thanks!

We are using IRedisClientsManager.

I updated to 5.11.1 from MyGet and still have the same issue.

Did you clear your NuGet packages cache, before redownloading v5.11.1, i.e

$ nuget locals all -clear

If so what’s the new StackTrace?

The problem has been resolved by commenting out the InitSchema() line (took a shot). Do I need this or may leaving it out cause other issues?

            // Register Redis as default Cache Provider
        container.Register<IRedisClientsManagerAsync>(new RedisManagerPool(AppSettings.Get<string>(SecretName.ConnectionStringRedis)));
        container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClientAsync());
        //  container.Resolve<ICacheClient>().InitSchema();
        RedisConfig.DefaultRetryTimeout = 30000;

No it’s only needed for caching providers that require creating a Cache Table, i.e. OrmLite & DynamoDB.

For any other Caching Provider it’s a NOOP so should not have any effect, I’m assuming your rebuild changed it to run the latest version or something.

Hi @bobk,

Something worth noting from the code you shared, you should use the standard registration of your IRedisClientManager and ICacheClient factory, not the Async versions, unless you are specifically handling the Resolve<T> yourself. CacheAsync cache functionality will be wired up to use the async clients in your services automatically. You should use the standard registration of:

container.Register<IRedisClientsManager>(
    new RedisManagerPool(
        AppSettings.Get<string>(SecretName.ConnectionStringRedis))); 

container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClient());

In your code, the line container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClientAsync()); is actually registering a factory for ValueTask<ICacheClientAsync> which won’t resolve from container.Resolve<ICacheClientAsync> as the registered types to not match.

Hope that helps :+1:.

2 Likes

Big help, thank you so much for your assistance!

1 Like