{"record":{"id":"df77e6aa2eb5c0fb","repo":"github/copilot-sdk","slug":"createsessionfsprovider-returned-null","errorCode":null,"errorMessage":"CreateSessionFsProvider returned null.","messagePattern":"CreateSessionFsProvider returned null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Client.cs","lineNumber":2159,"sourceCode":"\n        await Rpc.LlmInference.SetProviderAsync(cancellationToken);\n    }\n\n    private void ConfigureSessionFsHandlers(CopilotSession session, Func<CopilotSession, SessionFsProvider>? createSessionFsHandler)\n    {\n        if (_options.SessionFs is null)\n        {\n            return;\n        }\n\n        if (createSessionFsHandler is null)\n        {\n            throw new InvalidOperationException(\n                \"CreateSessionFsProvider is required in the session config when CopilotClientOptions.SessionFs is configured.\");\n        }\n\n        var provider = createSessionFsHandler(session)\n            ?? throw new InvalidOperationException(\"CreateSessionFsProvider returned null.\");\n\n        if (_options.SessionFs.Capabilities?.Sqlite == true && provider is not ISessionFsSqliteProvider)\n        {\n            throw new InvalidOperationException(\n                \"SessionFsConfig declares capabilities.sqlite but the provider does not implement ISessionFsSqliteProvider.\");\n        }\n\n        session.ClientSessionApis.SessionFs = provider;\n    }\n\n    private async Task VerifyProtocolVersionAsync(Connection connection, CancellationToken cancellationToken)\n    {\n        var handshakeTimestamp = Stopwatch.GetTimestamp();\n        var usedFallbackPing = false;\n        var maxVersion = SdkProtocolVersion.GetVersion();\n        int? serverVersion;\n        try\n        {","sourceCodeStart":2141,"sourceCodeEnd":2177,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L2141-L2177","documentation":"The session config did supply a CreateSessionFsProvider handler, but invoking it returned null. The client needs a concrete provider instance to attach to the session's filesystem APIs, so it throws instead of assigning a null provider.","triggerScenarios":"createSessionFsHandler(session) evaluates to null at Client.cs:2159 — the factory delegate returns null (or a null-valued expression) when called during session initialization with SessionFs configured.","commonSituations":"A factory like `_ => FindProvider()` where the lookup fails and returns null; conditional creation code returning null on platforms where the provider isn't available; forgetting the `new` in `MyProvider()` and returning a null field; DI container resolving no registration.","solutions":["Make CreateSessionFsProvider always return a valid ISessionFsProvider instance, or throw with a clear message inside the factory.","Fix the null-returning branch in the factory (failed lookup, missing registration, unsupported platform).","If the provider genuinely cannot be created, fail earlier with an explicit configuration error instead of returning null."],"exampleFix":"// before\nsessionConfig.CreateSessionFsProvider = _ => _lazyProvider?.Value; // null if not created\n\n// after\nsessionConfig.CreateSessionFsProvider = _ => _lazyProvider?.Value\n    ?? throw new InvalidOperationException(\"SessionFs provider not initialized\");","handlingStrategy":"validation","validationCode":"sessionConfig.CreateSessionFsProvider = session =>\n    CreateProvider(session) ?? throw new InvalidOperationException(\"Provider factory returned null\");","typeGuard":null,"tryCatchPattern":"try\n{\n    session = await client.CreateSessionAsync(sessionConfig);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"returned null\"))\n{\n    logger.LogError(ex, \"CreateSessionFsProvider factory returned null\");\n}","preventionTips":["Never write a provider factory with a nullable return path; throw explicitly on failure.","Test the factory against every supported platform/configuration.","Fail fast in DI setup if the provider implementation is unregistered."],"tags":["configuration","session-fs","null-provider"],"backgroundTag":"null-argument","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}