{"record":{"id":"b1dfabb4c8c597c5","repo":"github/copilot-sdk","slug":"ffi-runtime-library-not-found-at-fulllibrarypath","errorCode":null,"errorMessage":"FFI runtime library not found at '{fullLibraryPath}'.","messagePattern":"FFI runtime library not found at '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"dotnet/src/FfiRuntimeHost.cs","lineNumber":78,"sourceCode":"        _logger = logger;\n    }\n\n    /// <summary>The stream JSON-RPC reads server→client frames from.</summary>\n    public Stream ReceiveStream => _receiveStream;\n\n    /// <summary>The stream JSON-RPC writes client→server frames to.</summary>\n    public Stream SendStream => _sendStream\n        ?? throw new InvalidOperationException(\"FfiRuntimeHost has not been started.\");\n\n    /// <summary>\n    /// Loads the runtime cdylib and prepares the FFI host.\n    /// </summary>\n    public static FfiRuntimeHost Create(string libraryPath, string? cliEntrypoint, IReadOnlyDictionary<string, string>? environment, IReadOnlyList<string> args, ILogger logger)\n    {\n        var fullLibraryPath = Path.GetFullPath(libraryPath);\n        if (!File.Exists(fullLibraryPath))\n        {\n            throw new InvalidOperationException($\"FFI runtime library not found at '{fullLibraryPath}'.\");\n        }\n        PrepareNativeLibrary(fullLibraryPath);\n        return new FfiRuntimeHost(\n            fullLibraryPath,\n            cliEntrypoint is null ? null : Path.GetFullPath(cliEntrypoint),\n            environment,\n            args,\n            logger);\n    }\n\n    /// <summary>\n    /// The natural platform shared-library file name for the runtime cdylib, as\n    /// emitted by the .NET build (the .node file renamed to what the Rust cdylib\n    /// would be called on this OS).\n    /// </summary>\n    internal static string GetRuntimeLibraryFileName()\n    {\n        if (OperatingSystem.IsWindows()) return \"copilot_runtime.dll\";","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/FfiRuntimeHost.cs#L60-L96","documentation":"FfiRuntimeHost.Create resolves the runtime cdylib path and verifies it exists before loading it. This InvalidOperationException reports the fully-resolved path when the native runtime library file is missing, failing fast instead of inside the native loader.","triggerScenarios":"Calling Create with a libraryPath that does not exist on disk — wrong relative path, library not built/installed, wrong platform variant (linux-x64 vs osx), or insufficient resolve of a relative path from a different working directory.","commonSituations":"Deployment packages omit the native runtime binary; CI publishes for the wrong RID; app's working directory differs from dev so relative paths resolve differently; library deleted by cleanup or antivirus.","solutions":["Verify the resolved path in the message exists (ls / File.Exists) and fix libraryPath to point at the built cdylib (.so/.dylib/.dll)","Build/publish the native runtime for the target RID and include it in the output directory","Use an absolute path or resolve relative to AppContext.BaseDirectory instead of the current working directory"],"exampleFix":"// before\nvar host = FfiRuntimeHost.Create(\"libcopilot_runtime.so\", ...);\n// after\nvar libPath = Path.Combine(AppContext.BaseDirectory, \"runtimes\", \"linux-x64\", \"native\", \"libcopilot_runtime.so\");\nvar host = FfiRuntimeHost.Create(libPath, ...);","handlingStrategy":"validation","validationCode":"var full = Path.GetFullPath(libraryPath);\nif (!File.Exists(full)) throw new FileNotFoundException($\"FFI runtime library missing: {full}\", full);","typeGuard":"bool LibraryExists(string path) => File.Exists(Path.GetFullPath(path));","tryCatchPattern":"try { var host = FfiRuntimeHost.Create(libraryPath, ...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not found at\")) { /* fix path / publish native lib */ throw new ApplicationException(\"Runtime library missing\", ex); }","preventionTips":["Resolve library paths against AppContext.BaseDirectory, not the working directory","Include the native runtime for every target RID in publish output","Verify the artifact after deployment with a File.Exists smoke check"],"tags":["ffi","native-library","file","dotnet"],"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"}