{"record":{"id":"f137f9d179a52ba5","repo":"microsoft/FASTER","slug":"functions-not-provided-for-session","errorCode":null,"errorMessage":"Functions not provided for session","messagePattern":"Functions not provided for session","errorType":"exception","errorClass":"FasterException","httpStatus":null,"severity":"error","filePath":"cs/src/core/ClientSession/FASTERClientSession.cs","lineNumber":74,"sourceCode":"                    SessionVariableLengthStructSettings<Value, Input> sessionVariableLengthStructSettings = null, ReadCopyOptions readCopyOptions = default)\n                where Functions : IFunctions<Key, Value, Input, Output, Context>\n            {\n                return _fasterKV.ResumeSession<Input, Output, Context, Functions>(functions, sessionName, out commitPoint, sessionVariableLengthStructSettings, readCopyOptions);\n            }\n\n            /// <summary>\n            /// Start a new client session with FASTER.\n            /// </summary>\n            /// <param name=\"sessionName\">Name of session (optional)</param>\n            /// <param name=\"sessionVariableLengthStructSettings\">Session-specific variable-length struct settings</param>\n            /// <param name=\"readCopyOptions\"><see cref=\"ReadCopyOptions\"/> for this session; override those specified at FasterKV level, and may be overridden on individual Read operations</param>\n            /// <returns>Session instance</returns>\n            public ClientSession<Key, Value, Input, Output, Context, Functions> NewSession<Functions>(string sessionName = null, \n                    SessionVariableLengthStructSettings<Value, Input> sessionVariableLengthStructSettings = null, ReadCopyOptions readCopyOptions = default)\n                where Functions : IFunctions<Key, Value, Input, Output, Context>\n            {\n                if (_functions == null)\n                    throw new FasterException(\"Functions not provided for session\");\n\n                return _fasterKV.NewSession<Input, Output, Context, Functions>((Functions)_functions, sessionName, sessionVariableLengthStructSettings, readCopyOptions);\n            }\n\n            /// <summary>\n            /// Resume (continue) prior client session with FASTER, used during\n            /// recovery from failure.\n            /// </summary>\n            /// <param name=\"sessionName\">Name of previous session to resume</param>\n            /// <param name=\"commitPoint\">Prior commit point of durability for session</param>\n            /// <param name=\"sessionVariableLengthStructSettings\">Session-specific variable-length struct settings</param>\n            /// <param name=\"readCopyOptions\"><see cref=\"ReadCopyOptions\"/> for this session; override those specified at FasterKV level, and may be overridden on individual Read operations</param>\n            /// <returns>Session instance</returns>\n            public ClientSession<Key, Value, Input, Output, Context, Functions> ResumeSession<Functions>(string sessionName, out CommitPoint commitPoint,\n                    SessionVariableLengthStructSettings<Value, Input> sessionVariableLengthStructSettings = null, ReadCopyOptions readCopyOptions = default)\n                where Functions : IFunctions<Key, Value, Input, Output, Context>\n            {\n                if (_functions == null)","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/ClientSession/FASTERClientSession.cs#L56-L92","documentation":"FASTERClientSession.NewSession<Functions> requires the internal _functions field (set by the FASTER wrapper when the session was created) to hold an IFunctions instance. When none was provided, it cannot cast to the requested Functions type, so it throws FasterException instead of a NullReferenceException deep inside FasterKV.","triggerScenarios":"Calling NewSession<Functions>() on a FASTERClientSession whose functions were never supplied (e.g. session created without functions, or functions set to null).","commonSituations":"Constructing the client session wrapper without registering an IFunctions implementation, or clearing functions before opening a session; unit tests using partial stubs that leave _functions null.","solutions":["Provide an IFunctions<Key, Value, Input, Output, Context> instance to the FASTERClientSession before calling NewSession.","Ensure the FASTERClientSession constructor/factory path that sets _functions is used.","Check _functions for null (or expose a guard) before calling NewSession."],"exampleFix":"// before\nvar clientSession = new FASTERClientSession<Key, Value, Input, Output, Context>(fasterKV, ...); // functions: null\nclientSession.NewSession<MyFunctions>(); // throws\n\n// after\nvar clientSession = new FASTERClientSession<Key, Value, Input, Output, Context>(fasterKV, ..., functions: new MyFunctions());\nclientSession.NewSession<MyFunctions>(); // ok","handlingStrategy":"validation","validationCode":"if (clientSessionFunctions is null)\n    throw new InvalidOperationException(\"Functions must be provided to FASTERClientSession before NewSession\");\nclientSession.NewSession<MyFunctions>();","typeGuard":"bool HasFunctions<TK, TV, TI, TO, TC>(FASTERClientSession<TK, TV, TI, TO, TC> s) => s != null /* and functions accessor non-null */;","tryCatchPattern":"try\n{\n    var session = clientSession.NewSession<MyFunctions>();\n}\ncatch (FasterException ex) when (ex.Message.Contains(\"Functions not provided\"))\n{\n    // recreate wrapper with functions, then retry\n}","preventionTips":["Require IFunctions in the FASTERClientSession constructor (non-nullable).","Centralize session creation in a factory that always supplies functions.","Fail fast at wrapper construction if functions is null."],"tags":["csharp","faster","null-argument","session"],"backgroundTag":"null-argument","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}