{"record":{"id":"421d4e4cef632649","repo":"HangfireIO/Hangfire","slug":"exception-421d4e","errorCode":null,"errorMessage":"exception","messagePattern":"exception","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/ExceptionInfo.cs","lineNumber":29,"sourceCode":"// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU Lesser General Public License for more details.\n// \n// You should have received a copy of the GNU Lesser General Public \n// License along with Hangfire. If not, see <http://www.gnu.org/licenses/>.\n\nusing System;\nusing System.Text;\nusing Hangfire.Annotations;\nusing Hangfire.Common;\nusing Newtonsoft.Json;\n\nnamespace Hangfire\n{\n    public sealed class ExceptionInfo\n    {\n        public ExceptionInfo([NotNull] Exception exception)\n        {\n            if (exception == null) throw new ArgumentNullException(nameof(exception));\n\n            Message = exception.Message;\n            Type = TypeHelper.CurrentTypeSerializer(exception.GetType());\n\n            if (exception.InnerException != null)\n            {\n                InnerException = new ExceptionInfo(exception.InnerException);\n            }\n        }\n\n        [JsonConstructor]\n        public ExceptionInfo([NotNull] string type, [CanBeNull] string message, [CanBeNull] ExceptionInfo innerException)\n        {\n            Type = type ?? throw new ArgumentNullException(nameof(type));\n            Message = message;\n            InnerException = innerException;\n        }\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/ExceptionInfo.cs#L11-L47","documentation":"ExceptionInfo wraps a System.Exception (message, type name, optional inner) so it can be serialized into Hangfire job state. Its constructor rejects a null exception with ArgumentNullException(nameof(exception)) at ExceptionInfo.cs:29 because every field it populates is derived from that exception — with a null reference there is nothing to record.","triggerScenarios":"Calling new ExceptionInfo(null), or new ExceptionInfo(ex.InnerException) when ex.InnerException is null. In practice this surfaces inside Hangfire when persisting failed-job state, or in custom JobFilter/IStateMachine handlers / dashboard code that build an ExceptionInfo from an exception that can legitimately be null.","commonSituations":"Custom job filters, exception filters, or state-change handlers that pass a caught exception (or its InnerException) straight into new ExceptionInfo(...) without a null check. Also when porting code that assumed InnerException was always present.","solutions":["Null-check the exception before constructing ExceptionInfo: if (ex != null) info = new ExceptionInfo(ex).","When walking InnerException, recurse only when ex.InnerException != null (the class itself already guards this in its own ctor, so user code must too).","If your handler receives a possibly-null exception, fall back to storing a generic message instead of throwing.","Enable nullable reference types (NullableContextOptions) so the compiler flags null-argument paths at build time."],"exampleFix":"// before\nvar info = new ExceptionInfo(jobException.InnerException);\n// after\nvar info = jobException.InnerException != null\n    ? new ExceptionInfo(jobException.InnerException)\n    : null;","handlingStrategy":"validation","validationCode":"// before constructing\nif (exception == null)\n{\n    throw new ArgumentNullException(nameof(exception));\n}\nvar info = new ExceptionInfo(exception);","typeGuard":"static ExceptionInfo? SafeWrap(Exception? ex)\n    => ex != null ? new ExceptionInfo(ex) : null;","tryCatchPattern":null,"preventionTips":["Null-check exceptions (and their InnerException) before wrapping them in ExceptionInfo.","Enable nullable reference types so nullable exceptions are flagged at compile time.","In exception filters, treat the exception argument as potentially null.","Never assume InnerException is non-null when recursing."],"tags":["csharp","hangfire","argument-null","serialization","exception"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}