{"record":{"id":"efe2ebcd9d251613","repo":"github/copilot-sdk","slug":"copilotclientoptions-environment-is-not-supported","errorCode":null,"errorMessage":"CopilotClientOptions.Environment is not supported with RuntimeConnection.ForInProcess(): the in-process transport loads the native runtime into the shared host process, whose single environment block cannot carry per-client values. Set the variables on the host process environment instead.","messagePattern":"CopilotClientOptions\\.Environment is not supported with RuntimeConnection\\.ForInProcess\\(\\): the in-process transport loads the native runtime into the shared host process, whose single environment block cannot carry per-client values\\. Set the variables on the host process environment instead\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Client.cs","lineNumber":232,"sourceCode":"            }\n        }\n    }\n\n    /// <summary>\n    /// Validates environment-variable options against the resolved transport.\n    /// Per-client environment is only representable for child-process transports\n    /// (each client owns its own OS process). The in-process (FFI) transport\n    /// loads the native runtime into the shared host process, whose single\n    /// environment block cannot carry per-client values, so environment and\n    /// telemetry options that lower to environment variables are rejected there.\n    /// </summary>\n    private static void ValidateEnvironmentOptions(CopilotClientOptions options, RuntimeConnection connection)\n    {\n        if (connection is InProcessRuntimeConnection)\n        {\n            if (options.Environment is not null)\n            {\n                throw new ArgumentException(\n                    $\"{nameof(CopilotClientOptions)}.{nameof(CopilotClientOptions.Environment)} is not supported with \" +\n                    $\"{nameof(RuntimeConnection)}.{nameof(RuntimeConnection.ForInProcess)}(): the in-process transport \" +\n                    \"loads the native runtime into the shared host process, whose single environment block cannot carry \" +\n                    \"per-client values. Set the variables on the host process environment instead.\",\n                    nameof(options));\n            }\n\n            if (options.Telemetry is not null)\n            {\n                throw new ArgumentException(\n                    $\"{nameof(CopilotClientOptions)}.{nameof(CopilotClientOptions.Telemetry)} is not supported with \" +\n                    $\"{nameof(RuntimeConnection)}.{nameof(RuntimeConnection.ForInProcess)}(): telemetry configuration is \" +\n                    \"lowered to environment variables read by native runtime code running in the shared host process, so \" +\n                    \"per-client telemetry cannot be honored in-process. Configure telemetry via the host process \" +\n                    \"environment, or use a child-process transport.\",\n                    nameof(options));\n            }\n","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L214-L250","documentation":"CopilotClient throws this ArgumentException when CopilotClientOptions.Environment is set while using RuntimeConnection.ForInProcess(). The in-process transport loads the native runtime into the shared host process, which has a single environment block, so per-client environment variables cannot be applied. The library fails fast at construction rather than silently ignoring the values.","triggerScenarios":"new CopilotClient(options, RuntimeConnection.ForInProcess()) where options.Environment is a non-null dictionary of environment variables. Validation happens in ValidateEnvironmentOptions during CopilotClient construction.","commonSituations":"Sharing a CopilotClientOptions object between child-process and in-process connections; migrating code from ForStdio() to ForInProcess() without removing Environment; trying to inject API keys or proxy settings per client in-process.","solutions":["Remove Environment from CopilotClientOptions when using ForInProcess().","Set the needed variables on the host process environment before startup (e.g. launchSettings, Dockerfile, shell export).","Switch to RuntimeConnection.ForStdio() (ChildProcessRuntimeConnection) if per-client environment isolation is required."],"exampleFix":"// before\nvar options = new CopilotClientOptions { Environment = new Dictionary<string,string> { [\"GITHUB_TOKEN\"] = token } };\nvar client = new CopilotClient(options, RuntimeConnection.ForInProcess());\n// after\nvar options = new CopilotClientOptions(); // no Environment\nEnvironment.SetEnvironmentVariable(\"GITHUB_TOKEN\", token); // host process env\nvar client = new CopilotClient(options, RuntimeConnection.ForInProcess());","handlingStrategy":"validation","validationCode":"if (connection is InProcessRuntimeConnection && options.Environment is not null)\n    throw new InvalidOperationException(\"Set env vars on the host process when using ForInProcess().\");","typeGuard":"static bool CanUseOptionsEnvironment(RuntimeConnection c) => c is not InProcessRuntimeConnection;","tryCatchPattern":"try { client = new CopilotClient(options, connection); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Environment\")) { /* fall back to stdio or env-free options */ }","preventionTips":["Keep separate CopilotClientOptions per transport type","Configure host-level env vars in launch profiles/CI instead of per-client","Add a unit test constructing clients with each connection type"],"tags":["dotnet","configuration","in-process","environment-variables"],"backgroundTag":"conflicting-config-options","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"}