{"record":{"id":"e89cafddf5767d36","repo":"App-vNext/Polly","slug":"value-cannot-be-null-parameter-oncachemiss-e89caf","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onCacheMiss')","messagePattern":"Value cannot be null\\. \\(Parameter 'onCacheMiss'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Caching/CacheSyntax.cs","lineNumber":363,"sourceCode":"\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":345,"sourceCodeEnd":374,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Caching/CacheSyntax.cs#L345-L374","documentation":"Thrown at policy-construction time by the legacy Polly v7 base overload Policy.Cache(...) with full callbacks. onCacheMiss is invoked when no cached value is found; this detailed overload requires it to be non-null because the policy calls it on every cache miss. Polly throws ArgumentNullException to fail fast.","triggerScenarios":"Calling the full-callback Cache(...) overload with the onCacheMiss argument set to null.","commonSituations":"You supplied onCacheGet and onCachePut for telemetry but omitted onCacheMiss; you assumed all callbacks were optional in this overload (only the *Error callbacks are nullable); refactor left it null.","solutions":["Pass a non-null Action<Context,string> for onCacheMiss (e.g. an empty lambda (_) => { }).","If you do not need lifecycle telemetry, use a simpler overload.","Provide a shared static no-op action for callbacks you do not care about."],"exampleFix":"// before\nPolicy.Cache(provider, ttlStrategy, keyFunc, onGet, null, onPut, onGetErr, onPutErr);\n// after\nPolicy.Cache(provider, ttlStrategy, keyFunc, onGet, (ctx, key) => { /* log miss */ }, onPut, onGetErr, onPutErr);","handlingStrategy":"validation","validationCode":"if (onCacheMiss is null) throw new InvalidOperationException(\"onCacheMiss is required by this overload.\");\nvar policy = Policy.Cache(cacheProvider, ttlStrategy, keyFunc, onGet, onCacheMiss, onPut, onGetErr, onPutErr);","typeGuard":"static bool IsCallbackValid(System.Action<Polly.Context,string>? a) => a is not null;","tryCatchPattern":null,"preventionTips":["Supply a no-op lambda for callbacks you do not care about.","Use a simpler overload if lifecycle telemetry is unnecessary.","Keep all callback arguments together in one builder method."],"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"}