{"record":{"id":"5522f7e33d8734bf","repo":"github/copilot-sdk","slug":"in-process-ffi-runtime-library-not-found-at-sear","errorCode":null,"errorMessage":"In-process FFI runtime library not found at '<searchedRuntime>'.","messagePattern":"In-process FFI runtime library not found at '<searchedRuntime>'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Client.cs","lineNumber":427,"sourceCode":"                        ffiArgs.Add(\"--no-auto-login\");\n                    }\n                    if (_options.SessionIdleTimeoutSeconds is > 0)\n                    {\n                        ffiArgs.AddRange([\"--session-idle-timeout\", _options.SessionIdleTimeoutSeconds.Value.ToString(CultureInfo.InvariantCulture)]);\n                    }\n                    if (_options.EnableRemoteSessions)\n                    {\n                        ffiArgs.Add(\"--remote\");\n                    }\n\n                    var explicitCliPath = System.Environment.GetEnvironmentVariable(\"COPILOT_CLI_PATH\");\n                    if (string.IsNullOrEmpty(explicitCliPath))\n                    {\n                        explicitCliPath = null;\n                    }\n                    var ffiRuntimePath = explicitCliPath is null\n                        ? GetBundledNativePath(FfiRuntimeHost.GetRuntimeLibraryFileName(), out var searchedRuntime)\n                            ?? throw new InvalidOperationException(\n                                $\"In-process FFI runtime library not found at '{searchedRuntime}'.\")\n                        : ResolveRuntimePathForExplicitCli(explicitCliPath);\n                    var ffiHost = FfiRuntimeHost.Create(\n                        ffiRuntimePath,\n                        explicitCliPath,\n                        ffiEnvironment,\n                        ffiArgs,\n                        _logger);\n                    _ffiHost = ffiHost;\n                    await ffiHost.StartAsync(ct);\n                    connection = await ConnectToServerAsync(null, null, null, null, ct, ffiHost);\n                }\n                else if (_connection is UriRuntimeConnection)\n                {\n                    // External runtime\n                    _actualPort = _optionsPort;\n                    connection = await ConnectToServerAsync(null, _optionsHost, _optionsPort, null, ct);\n                }","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L409-L445","documentation":"StartAsync throws this InvalidOperationException when the in-process FFI transport cannot locate the native runtime library. GetBundledNativePath searched the expected locations (recorded in 'searchedRuntime') and found nothing, and no explicit CLI path was provided to resolve the library from.","triggerScenarios":"Creating a CopilotClient with RuntimeConnection.ForInProcess() and calling StartAsync/EnsureConnectedAsync when the native runtime library was not shipped or is missing from the bundle, and no explicitCliPath was configured.","commonSituations":"Publishing/trimming a .NET app that dropped the native library from the output; running on an unsupported platform/architecture so the bundled path doesn't match; copying assemblies without the native runtime files; missing NuGet native assets package.","solutions":["Check the searched path in the message and verify the native runtime library exists there or next to the app binaries.","Set an explicit CLI/runtime path so ResolveRuntimePathForExplicitCli is used instead of the bundled lookup.","Reinstall/restore the NuGet package that ships the native runtime, and ensure publish includes native libraries (no aggressive trimming of native assets).","Fall back to RuntimeConnection.ForStdio() which spawns the CLI as a child process instead of loading the native library."],"exampleFix":"// before\nvar client = new CopilotClient(options, RuntimeConnection.ForInProcess()); // runtime lib missing\n// after - point at the runtime explicitly, or use stdio\nvar client = new CopilotClient(options with { CliPath = \"/path/to/copilot\" }, RuntimeConnection.ForInProcess());\n// or\nvar client = new CopilotClient(options, RuntimeConnection.ForStdio());","handlingStrategy":"fallback","validationCode":"var libPath = GetBundledNativePath(FfiRuntimeHost.GetRuntimeLibraryFileName(), out _);\nif (libPath is null && explicitCliPath is null)\n    Console.Error.WriteLine(\"Native FFI runtime missing; falling back to stdio transport.\");","typeGuard":"static bool FfiRuntimeAvailable(string? explicitCliPath) => explicitCliPath is not null || File.Exists(Path.Combine(AppContext.BaseDirectory, FfiRuntimeHost.GetRuntimeLibraryFileName()));","tryCatchPattern":"try { client = new CopilotClient(options, RuntimeConnection.ForInProcess()); await client.StartAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"FFI runtime library not found\")) { client = new CopilotClient(options, RuntimeConnection.ForStdio()); await client.StartAsync(); }","preventionTips":["Ensure the NuGet package shipping native runtime assets is referenced","Verify publish output includes native libraries for the target RID","Smoke-test the in-process transport on each supported platform in CI"],"tags":["dotnet","native-library","ffi","file-not-found","startup"],"backgroundTag":"file-not-found","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"}