Cache policy gives unhelpful exception on sync/async config/execution mismatch
See original GitHub issueI am following the samples to implement cache but I’m getting an exception during the call:
This is the policiy definition:
var cachePolicy = Policy.Cache(new MemoryCacheProvider(MemoryCache.Default), TimeSpan.FromMinutes(5))
Then this is the call:
return cachePolicy.ExecuteAsync(async () => await _webService.someMethodAsync());
And this is the error it throws:
Value cannot be null. Parameter name: nonGenericCacheProvider" at Polly.Caching.GenericCacheProviderAsync'1..ctor(IAsyncCacheProvider nonGenericCacheProvider)
What am I missing? I think this pretty much matches the samples offered in the Readme.md, but still no idea how to get rid of that exception.
BTW: the ExecuteAsync
overload to set Context
and set the operationKey
shows as deprecated, something not mentioned in documentation.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
@CesarD For asynchronous executions using
ExecuteAsync(...)
, the policy must be defined as an asynchronous policy, thus:All policies should give a helpful exception message explaining that, if sync/async are mixed incorrectly, but this case has escaped that. I’ll fix to make sure it gives a helpful exception.
Thanks for spotting the deprecated overload quoted in the cache documentation: it’ll be corrected in both the readme and wiki.
@CesarD Thanks for the feedback. Extra clarification added: