{"record":{"id":"47b32d3cdebb387e","repo":"HangfireIO/Hangfire","slug":"cronexpression","errorCode":null,"errorMessage":"cronExpression","messagePattern":"cronExpression","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/RecurringJob.cs","lineNumber":58,"sourceCode":"                }\n            }\n            set\n            {\n                lock (ManagerFactoryLock)\n                {\n                    _managerFactory = value;\n                }\n            }\n        }\n\n        [Obsolete(\"Please use an overload with the explicit recurringJobId parameter and RecurringJobOptions instead. Will be removed in 2.0.0.\")]\n        public static void AddOrUpdate(\n            [NotNull, InstantHandle] Expression<Action> methodCall,\n            [NotNull] Func<string> cronExpression,\n            [CanBeNull] TimeZoneInfo timeZone = null,\n            [NotNull] string queue = EnqueuedState.DefaultQueue)\n        {\n            if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression));\n            AddOrUpdate(methodCall, cronExpression(), timeZone, queue);\n        }\n\n        [Obsolete(\"Please use an overload with the explicit recurringJobId parameter instead. Will be removed in 2.0.0.\")]\n        public static void AddOrUpdate(\n            [NotNull, InstantHandle] Expression<Action> methodCall,\n            [NotNull] Func<string> cronExpression,\n            [NotNull] RecurringJobOptions options)\n        {\n            if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression));\n            AddOrUpdate(methodCall, cronExpression(), options);\n        }\n\n        [Obsolete(\"Please use an overload with the explicit recurringJobId parameter and RecurringJobOptions instead. Will be removed in 2.0.0.\")]\n        public static void AddOrUpdate<T>(\n            [NotNull, InstantHandle] Expression<Action<T>> methodCall,\n            [NotNull] Func<string> cronExpression,\n            [CanBeNull] TimeZoneInfo timeZone = null,","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/RecurringJob.cs#L40-L76","documentation":"Thrown by the obsolete RecurringJob.AddOrUpdate(Expression<Action>, Func<string> cronExpression, ...) overload when the cronExpression factory delegate is null. Hangfire accepts a Func<string> so the cron expression can be evaluated lazily. A null factory means there is no way to obtain the schedule.","triggerScenarios":"Calling RecurringJob.AddOrUpdate(() => MyMethod(), cronExpression: null) or passing a variable that is null for the Func<string> cronExpression parameter of this specific obsolete overload.","commonSituations":"Migrating from the obsolete overload and forgetting to supply the cron factory. Storing cron in configuration that resolves to null. Using a helper that conditionally returns null from a cron-selection function.","solutions":["Provide a non-null Func<string> that returns the cron expression, e.g. () => Cron.Daily().","Migrate to the non-obsolete overload that takes an explicit recurringJobId and a string cronExpression with RecurringJobOptions.","If the cron source may be absent, validate it before calling AddOrUpdate and skip or log instead of passing null."],"exampleFix":"// before\nRecurringJob.AddOrUpdate(() => Job.Run(), cronExpression: null);\n\n// after\nRecurringJob.AddOrUpdate(\"my-job\", () => Job.Run(), Cron.Daily());","handlingStrategy":"validation","validationCode":"Func<string> cronFactory = () => _config[\"Cron\"];\nif (cronFactory == null) throw new InvalidOperationException(\"Cron factory is not configured.\");\nRecurringJob.AddOrUpdate(() => Work(), cronFactory, TimeZoneInfo.Utc);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Migrate away from the obsolete AddOrUpdate overload to the explicit-id string-cron version.","Resolve cron from config and validate it is non-null at startup.","Use Cron helper methods (Cron.Daily()) as the factory return to avoid null."],"tags":["recurring-job","cron","argument-null","obsolete"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}