{"record":{"id":"9f6bf991da5e8b44","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-finallyaction","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'finallyAction')","messagePattern":"Value cannot be null\\. \\(Parameter 'finallyAction'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs","lineNumber":1144,"sourceCode":"                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n\n            return source.Provider.CreateQuery<TSource>(Expression.Call(Expand__TSource__2__2(typeof(TSource)), source.Expression, selector));\n        }\n\n        private static MethodInfo? s_Finally__TSource__2__0;\n        \n        private static MethodInfo Finally__TSource__2__0(Type TSource) =>\n            (s_Finally__TSource__2__0 ??\n            (s_Finally__TSource__2__0 = new Func<IAsyncQueryable<object>, Action, IAsyncQueryable<object>>(Finally<object>).GetMethodInfo()!.GetGenericMethodDefinition())).MakeGenericMethod(TSource);\n\n        public static IAsyncQueryable<TSource> Finally<TSource>(this IAsyncQueryable<TSource> source, Action finallyAction)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (finallyAction == null)\n                throw new ArgumentNullException(nameof(finallyAction));\n\n            return source.Provider.CreateQuery<TSource>(Expression.Call(Finally__TSource__2__0(typeof(TSource)), source.Expression, Expression.Constant(finallyAction, typeof(Action))));\n        }\n\n        private static MethodInfo? s_Finally__TSource__2__1;\n        \n        private static MethodInfo Finally__TSource__2__1(Type TSource) =>\n            (s_Finally__TSource__2__1 ??\n            (s_Finally__TSource__2__1 = new Func<IAsyncQueryable<object>, Expression<Func<Task>>, IAsyncQueryable<object>>(Finally<object>).GetMethodInfo()!.GetGenericMethodDefinition())).MakeGenericMethod(TSource);\n\n        public static IAsyncQueryable<TSource> Finally<TSource>(this IAsyncQueryable<TSource> source, Expression<Func<Task>> finallyAction)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (finallyAction == null)\n                throw new ArgumentNullException(nameof(finallyAction));\n\n            return source.Provider.CreateQuery<TSource>(Expression.Call(Finally__TSource__2__1(typeof(TSource)), source.Expression, finallyAction));","sourceCodeStart":1126,"sourceCodeEnd":1162,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive.Async.Providers/System/Linq/AsyncQueryableEx.Generated.cs#L1126-L1162","documentation":"Thrown by the generated AsyncQueryableEx.Finally extension when finallyAction is null. The action is embedded into the expression tree as Expression.Constant(finallyAction, typeof(Action)), which cannot be null, so the library validates it up front.","triggerScenarios":"Calling Finally(source, null) or passing an Action field/delegate variable that was never assigned.","commonSituations":"Optional cleanup hooks configured externally where the hook was not registered; delegates wired via events or DI that remain null in some environments.","solutions":["Pass a real action, e.g. q.Finally(() => logger.Flush())","If cleanup is optional, skip the Finally call when the action is null instead of passing null","Default the action to a no-op: () => {}","Check the DI/config registration that should provide the callback"],"exampleFix":"// before\nAction cleanup = GetCleanupHook(); // null when not configured\nvar q = source.Finally(cleanup);\n// after\nvar cleanup = GetCleanupHook();\nvar q = cleanup != null ? source.Finally(cleanup) : source;","handlingStrategy":"validation","validationCode":"if (finallyAction is null) throw new ArgumentNullException(nameof(finallyAction));","typeGuard":"bool HasCleanup(Action? a) => a is not null;","tryCatchPattern":"try { query = source.Finally(action); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"finallyAction\") { throw new InvalidOperationException(\"Finally cleanup action was null\", ex); }","preventionTips":["Only call Finally when a cleanup hook actually exists; conditionally apply it otherwise","Default optional hooks to a no-op delegate","Verify DI/event registrations that supply the cleanup callback"],"tags":["csharp","linq","argument-null","async-queryable"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}