{"record":{"id":"2127af135c41db95","repo":"App-vNext/Polly","slug":"value-cannot-be-null-parameter-oncacheget-2127af","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onCacheGet')","messagePattern":"Value cannot be null\\. \\(Parameter 'onCacheGet'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Caching/CacheSyntax.cs","lineNumber":358,"sourceCode":"    {\n        if (cacheProvider == null)\n        {\n            throw new ArgumentNullException(nameof(cacheProvider));\n        }\n\n        if (ttlStrategy == null)\n        {\n            throw new ArgumentNullException(nameof(ttlStrategy));\n        }\n\n        if (cacheKeyStrategy == null)\n        {\n            throw new ArgumentNullException(nameof(cacheKeyStrategy));\n        }\n\n        if (onCacheGet == null)\n        {\n            throw new ArgumentNullException(nameof(onCacheGet));\n        }\n\n        if (onCacheMiss == null)\n        {\n            throw new ArgumentNullException(nameof(onCacheMiss));\n        }\n\n        if (onCachePut == null)\n        {\n            throw new ArgumentNullException(nameof(onCachePut));\n        }\n\n        return new CachePolicy(cacheProvider, ttlStrategy, cacheKeyStrategy, onCacheGet, onCacheMiss, onCachePut, onCacheGetError, onCachePutError);\n    }\n}\n","sourceCodeStart":340,"sourceCodeEnd":374,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Caching/CacheSyntax.cs#L340-L374","documentation":"Thrown at policy-construction time by the legacy Polly v7 base overload Policy.Cache(...) with full callbacks. onCacheGet is the action invoked when a value is successfully read from cache; even though it is an optional-feeling callback, this overload requires it to be non-null (it is invoked on every cache hit). Polly fails fast with ArgumentNullException.","triggerScenarios":"Calling the full-callback Cache(...) overload with the onCacheGet argument set to null.","commonSituations":"You wired some lifecycle callbacks but left onCacheGet null; you assumed callbacks were optional in this detailed overload (they are not — only the *Error callbacks accept null); overload-resolution put you on this method.","solutions":["Pass a non-null Action<Context,string> for onCacheGet (e.g. an empty lambda (_) => { }).","If you do not need these callbacks, use a simpler overload that does not require them.","Use the helper EmptyCallback from Polly if available, or define a static no-op action."],"exampleFix":"// before\nPolicy.Cache(provider, ttlStrategy, keyFunc, null, onMiss, onPut, onGetErr, onPutErr);\n// after\nPolicy.Cache(provider, ttlStrategy, keyFunc, (ctx, key) => { /* log hit */ }, onMiss, onPut, onGetErr, onPutErr);","handlingStrategy":"validation","validationCode":"if (onCacheGet is null) throw new InvalidOperationException(\"onCacheGet is required by this overload (use a simpler overload or a no-op).\");\nvar policy = Policy.Cache(cacheProvider, ttlStrategy, keyFunc, onCacheGet, onMiss, onPut, onGetErr, onPutErr);","typeGuard":"static bool IsCallbackValid(System.Action<Polly.Context,string>? a) => a is not null;","tryCatchPattern":null,"preventionTips":["Remember that in the full-callback overload only the *Error callbacks are nullable; onGet/onMiss/onPut are required.","Provide a shared static no-op action for callbacks you do not need.","Prefer a simpler overload when you do not require telemetry callbacks."],"tags":["polly","caching","legacy-v7","argument-null","cache-callbacks"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}