You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apple M1上.NET 6调用Firestore报libgrpc_csharp_ext.x64.dylib加载错误

问题根因

该错误由Google.Cloud.Firestore 2.4.0默认依赖的原生gRPC实现Grpc.Core导致,该库已停止维护,其原生二进制文件在macOS Big Sur + .NET 6 RC环境下存在签名、架构兼容类加载问题。

推荐解决方案(优先选择)

升级依赖并切换到托管gRPC实现,完全规避原生库兼容问题:

  • 第一步:更新NuGet包
    将Google.Cloud.Firestore升级到2.6.0及以上稳定版,同时安装Google.Api.Gax.Grpc.GrpcNetClient包。
  • 第二步:添加gRPC配置
    调整ConfigureFirestoreEmulator方法代码,显式指定使用托管gRPC实现,并开启本地gRPC非加密通道支持:
    static void ConfigureFirestoreEmulator(IConfigurationBuilder configurationBuilder)
    {
        // 开启.NET 6下非加密HTTP2 gRPC请求支持
        AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
        Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", "localhost:8080");
        // 全局指定gRPC使用Grpc.Net.Client托管实现,不依赖原生库
        Google.Api.Gax.Grpc.GrpcAdapter.Default = Google.Api.Gax.Grpc.GrpcNetClientAdapter.Default;
    
        var db = new FirestoreDbBuilder
        {
            ProjectId = "dev",
            EmulatorDetection = Google.Api.Gax.EmulatorDetection.EmulatorOnly
        }.Build();
    }
    

备选解决方案(不升级Firestore版本时使用)

如果暂时无法升级Firestore包,可通过修复原生库签名/指定架构解决:

  • 方案1:手动签名原生库
    先安装Xcode命令行工具:
    xcode-select --install
    
    对报错路径的原生库执行自签名:
    codesign -f -s - /Users/[user]/Code/[project]/platform/WebApi/bin/Release/net6.0/runtimes/osx-x64/native/libgrpc_csharp_ext.x64.dylib
    
    完成后到系统「设置>安全与隐私>通用」中允许该库运行。
  • 方案2:指定运行架构
    如果你使用的是M1系列Mac,在项目.csproj文件中添加运行时标识配置:
    <PropertyGroup>
      <RuntimeIdentifier>osx-x64</RuntimeIdentifier>
    </PropertyGroup>
    
    运行项目时指定架构:
    dotnet run -r osx-x64
    

验证步骤

  1. 执行firebase emulators:start确认Firestore模拟器正常启动,8080端口无占用
  2. 清理项目缓存后重新构建运行即可。

内容的提问来源于stack exchange,提问作者Frankely Diaz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 11:27:05