首页 > 解决方案 > 如何修复 C# 中的“加载本机库时出错。在任何可能的位置都找不到”错误?

问题描述

我正在实现 Google Text-to-Speech API,我需要使用Channel该类将凭据放入其中。

但是当我执行该credential.ToChannelCredentials()方法时,会Error loading native library. Not found in any of the possible locations出现错误

我查看了错误抛出给我的路径,我确认该方法尝试到达grpc_csharp_ext.x86.dll项目 bin 文件夹中的 de,但文件位于C:\Users\<user>\.nuget\packages\grpc.core\1.18.0\runtimes\win\native

为了测试,我尝试直接在 bin 中从该路径复制文件并且它有效,但我知道这是不对的

我的代码:


    var credential = GoogleCredential.FromFile(MyJSON).CreateScoped(TextToSpeechClient.DefaultScopes);
    var channel = new Channel(TextToSpeechClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials()); // trow the error here
    TextToSpeechClient client = TextToSpeechClient.Create(channel);

我希望程序获得 .dll 的正确路径,但正试图从我项目的文件夹 bin 中获取

grpc.core版本1.18.0

标签: c#visual-studiotext-to-speechgrpc

解决方案


推荐阅读