Dialogflow - 检测意图冻结 - C#

Dialogflow - Detect Intent freezes - C#

我已经设置了一个 dialogflow 代理,我正在尝试编写 C# 代码来与它集成。 但我的问题是;代码只是冻结在这个方法上:DetectIntent.

这是我在项目中安装的 Google NuGet 包:

  • Google.Api.CommonProtos (v1.7.0)
  • Google.Api.Gax (v2.10.0)
  • Google.Api.Gax.Grpc (v2.10.0)
  • Google.Api.Gax.Rest (v2.10.0)
  • Google.Apis (v1.43.0)
  • Google.Apis.Auth (v1.43.0)
  • Google.Apis.Core (v1.43.0)
  • Google.Apis.Dialogflow.v2 (v1.40.2.1612)
  • Google.Apis.Storage.v1 (v1.43.0.1791)
  • Google.Cloud.Dialogflow.V2 (v1.2.0)
  • Google.Cloud.Language.V1 (v1.4.0)
  • Google.Cloud.Storage.V1 (v2.5.0)
  • Google.LongRunning (v1.1.0)
  • Google.Protobuf (v3.11.2)
  • Grpc.Auth (v1.22.1)
  • Grpc.Core (v1.22.1)
  • Grpc.Core.Api (v2.26.0)

然后我按照这个link进行身份验证:https://cloud.google.com/docs/authentication/production

所以我做了这个方法:

public static Grpc.Core.Channel AuthExplicitForChannel(string theProjectID, string theServiceAccountJSONFilePath)
{
    GoogleCredential googleCredential = GoogleCredential.FromFile(theServiceAccountJSONFilePath).CreateScoped(LanguageServiceClient.DefaultScopes);
    Grpc.Core.Channel mainChannel = new Grpc.Core.Channel(LanguageServiceClient.DefaultEndpoint.ToString(), googleCredential.ToChannelCredentials());
    return mainChannel;
}

这些用法:

using Grpc.Auth;
using Google.Protobuf;
using Google.LongRunning;
using Google.Api.Gax;
using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dialogflow.V2;
using static Google.Cloud.Dialogflow.V2.Intent.Types;
using Google.Cloud.Language.V1;
using Google.Cloud.Storage.V1;
using Google.Apis.Dialogflow.v2.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Storage.v1.Data;

然后我跟着这个link:https://cloud.google.com/dialogflow/docs/quick/api#detect-intent-text-csharp

然后我做了这个代码:

...

// Session
Grpc.Core.Channel mainChannel = DialogflowManipulation.AuthExplicitForChannel(projectID, serviceAccountKeyJSONFilePath);
SessionsClient mainSessionsClient = SessionsClient.Create(mainChannel);
SessionName mainSessionName = new SessionName(projectID, sessionID);

// Input
TextInput mainTextInput = new TextInput() { Text = text, LanguageCode = languageCode };
QueryInput mainQueryInput = new QueryInput() { Text = mainTextInput };

// Detect Intent
DetectIntentResponse response = mainSessionsClient.DetectIntent(mainSessionName, mainQueryInput);

...

我在调试模式下查看调试输出时发现,输出在它挂起后/挂起时打印:

Exception thrown: 'System.MissingMethodException' in Grpc.Core.dll

执行只是挂在最后一行 .DetectIntent

我哪里错了?

任何帮助/建议将不胜感激。

我发现了问题:

我猜问题是我安装的软件包版本不兼容。

我的 Grpc.Core(v1.22.1) 但我的 Grpc.Core .Api(v2.26.0) 上。 当我将 Grpc.Core.Api 版本更改为 (v1.22.1) 并再次尝试时;我的系统不再挂起,我得到了回应。我也没有得到调试输出打印:Exception thrown: 'System.MissingMethodException' in Grpc.Core.dll 了。

感谢 Marc Asmar 提供的有用评论和链接。