{"record":{"id":"ae73eb8251e29c3c","repo":"App-vNext/Polly","slug":"value-cannot-be-null-parameter-oncacheput-ae73eb","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onCachePut')","messagePattern":"Value cannot be null\\. \\(Parameter 'onCachePut'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Caching/CacheSyntax.cs","lineNumber":368,"sourceCode":"\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":350,"sourceCodeEnd":374,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Caching/CacheSyntax.cs#L350-L374","documentation":"Thrown at policy-construction time by the legacy Polly v7 base overload Policy.Cache(...) with full callbacks. onCachePut is invoked after a fresh value is written to cache; this detailed overload requires it non-null and invokes it on every cache store. Polly validates it up front with ArgumentNullException.","triggerScenarios":"Calling the full-callback Cache(...) overload with the onCachePut argument set to null.","commonSituations":"You supplied onCacheGet/onCacheMiss but omitted onCachePut; you assumed callbacks were optional in this overload; refactor left it null.","solutions":["Pass a non-null Action<Context,string> for onCachePut (e.g. an empty lambda (_) => { }).","If you do not need lifecycle telemetry, use a simpler overload.","Use a shared static no-op action for callbacks you do not use."],"exampleFix":"// before\nPolicy.Cache(provider, ttlStrategy, keyFunc, onGet, onMiss, null, onGetErr, onPutErr);\n// after\nPolicy.Cache(provider, ttlStrategy, keyFunc, onGet, onMiss, (ctx, key) => { /* log put */ }, onGetErr, onPutErr);","handlingStrategy":"validation","validationCode":"if (onCachePut is null) throw new InvalidOperationException(\"onCachePut is required by this overload.\");\nvar policy = Policy.Cache(cacheProvider, ttlStrategy, keyFunc, onGet, onMiss, onCachePut, onGetErr, onPutErr);","typeGuard":"static bool IsCallbackValid(System.Action<Polly.Context,string>? a) => a is not null;","tryCatchPattern":null,"preventionTips":["Provide a no-op action for callbacks you do not need.","Prefer the simpler overload without explicit callbacks.","Centralize callback wiring to avoid leaving one null."],"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"}