github/copilot-sdk · critical · InvalidOperationException
FFI runtime library not found at
Error message
FFI runtime library not found at '{fullLibraryPath}'. What it means
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.
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
Example fix
// before
var host = FfiRuntimeHost.Create("libcopilot_runtime.so", ...);
// after
var libPath = Path.Combine(AppContext.BaseDirectory, "runtimes", "linux-x64", "native", "libcopilot_runtime.so");
var host = FfiRuntimeHost.Create(libPath, ...); Defensive patterns
Strategy: validation
Validate before calling
var full = Path.GetFullPath(libraryPath);
if (!File.Exists(full)) throw new FileNotFoundException($"FFI runtime library missing: {full}", full); Type guard
bool LibraryExists(string path) => File.Exists(Path.GetFullPath(path));
Try / catch
try { var host = FfiRuntimeHost.Create(libraryPath, ...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("not found at")) { /* fix path / publish native lib */ throw new ApplicationException("Runtime library missing", ex); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- In-process FFI runtime library not found at
- FFI runtime library not found. Looked for
- An in-process FFI runtime library is already loaded from
- FFI runtime library not found at
- copilot_runtime_host_start failed
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/b1dfabb4c8c597c5.
Report an issue: GitHub.
Appendix: source
Thrown at dotnet/src/FfiRuntimeHost.cs:78
_logger = logger;
}
/// <summary>The stream JSON-RPC reads server→client frames from.</summary>
public Stream ReceiveStream => _receiveStream;
/// <summary>The stream JSON-RPC writes client→server frames to.</summary>
public Stream SendStream => _sendStream
?? throw new InvalidOperationException("FfiRuntimeHost has not been started.");
/// <summary>
/// Loads the runtime cdylib and prepares the FFI host.
/// </summary>
public static FfiRuntimeHost Create(string libraryPath, string? cliEntrypoint, IReadOnlyDictionary<string, string>? environment, IReadOnlyList<string> args, ILogger logger)
{
var fullLibraryPath = Path.GetFullPath(libraryPath);
if (!File.Exists(fullLibraryPath))
{
throw new InvalidOperationException($"FFI runtime library not found at '{fullLibraryPath}'.");
}
PrepareNativeLibrary(fullLibraryPath);
return new FfiRuntimeHost(
fullLibraryPath,
cliEntrypoint is null ? null : Path.GetFullPath(cliEntrypoint),
environment,
args,
logger);
}
/// <summary>
/// The natural platform shared-library file name for the runtime cdylib, as
/// emitted by the .NET build (the .node file renamed to what the Rust cdylib
/// would be called on this OS).
/// </summary>
internal static string GetRuntimeLibraryFileName()
{
if (OperatingSystem.IsWindows()) return "copilot_runtime.dll";View on GitHub (pinned to cd8cf15dc3)