github/copilot-sdk · error · InvalidOperationException

Could not determine a napi-rs prebuilds folder for FFI…

Error message

Could not determine a napi-rs prebuilds folder for FFI hosting.

What it means

GetNapiPrebuildsFolder builds the `<node-platform>-<arch>` folder name (e.g. win32-x64) from the current runtime's platform and architecture. If either cannot be determined it returns null and GetNapiPrebuildsFolderOrThrow throws this InvalidOperationException. It is a guard so FFI library resolution never silently probes an invalid prebuilds path.

Solutions

  1. Run the app on a supported platform/arch (win32/win-arm64, linux-x64/arm64, darwin-x64/arm64).
  2. Check RuntimeInformation.OSArchitecture and ProcessArchitecture locally to see what the runtime reports; fix RID mismatch in the publish profile if it reports an odd value.
  3. Use stdio (CLI process) hosting instead of FFI hosting on unsupported platforms.

Example fix

// before: FFI hosting on an untested arch
copilot = new CopilotClient(); // throws on e.g. linux-armel

// after: gate FFI hosting on known arches
var arch = RuntimeInformation.ProcessArchitecture;
bool ffiSupported = arch is Architecture.X64 or Architecture.Arm64;
copilot = ffiSupported ? new CopilotClient() : new CopilotClient(useStdio: true);
Defensive patterns

Strategy: validation

Validate before calling

var arch = RuntimeInformation.ProcessArchitecture;
var os = RuntimeInformation.OSDescription;
bool supported = arch is Architecture.X64 or Architecture.Arm64;
if (!supported) throw new PlatformNotSupportedException(os);

Try / catch

try { folder = GetNapiPrebuildsFolder(); }
catch (InvalidOperationException) { /* fall back to stdio hosting */ }

Prevention

When it happens

Trigger: FFI startup calls GetNapiPrebuildsFolderOrThrow while RuntimeInformation's OSArchitecture/ProcessArchitecture maps to an unknown platform or architecture (null result).

Common situations: Running on an exotic or unsupported platform/arch combination (e.g. linux-armel, freebsd) or inside an environment where the .NET runtime cannot report the architecture; mismatched self-contained publish settings.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/75042766a14f3cff. Report an issue: GitHub.

Appendix: source

Thrown at dotnet/src/Client.cs:2609

                ? "linuxmusl"
                : "linux";
        }
        else if (OperatingSystem.IsMacOS()) platform = "darwin";
        else return null;

        var arch = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture switch
        {
            System.Runtime.InteropServices.Architecture.X64 => "x64",
            System.Runtime.InteropServices.Architecture.Arm64 => "arm64",
            _ => null,
        };

        return arch != null ? $"{platform}-{arch}" : null;
    }

    private static string GetNapiPrebuildsFolderOrThrow() =>
        GetNapiPrebuildsFolder()
        ?? throw new InvalidOperationException("Could not determine a napi-rs prebuilds folder for FFI hosting.");

    private static (string FileName, IEnumerable<string> Args) ResolveCliCommand(string cliPath, IEnumerable<string> args)
    {
        var isJsFile = cliPath.EndsWith(".js", StringComparison.OrdinalIgnoreCase);

        if (isJsFile)
        {
            return ("node", new[] { cliPath }.Concat(args));
        }

        return (cliPath, args);
    }

    private async Task<Connection> ConnectToServerAsync(Process? cliProcess, string? tcpHost, int? tcpPort, ProcessStderrPump? stderrPump, CancellationToken cancellationToken, FfiRuntimeHost? ffiHost = null)
    {
        var setupTimestamp = Stopwatch.GetTimestamp();
        NetworkStream? networkStream = null;
        JsonRpc? rpc = null;

View on GitHub (pinned to cd8cf15dc3)