0
votes

I've set up a dialogflow agent and I'm trying to write C# code to integrate with it. But my problem is; the code just freezes on this method: DetectIntent.

Here's the Google NuGet Packages I've installed on my project:

  • 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)

Then I followed this link for authentication: https://cloud.google.com/docs/authentication/production

So I've made this method:

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;
}

With these usings:

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;

Then I followed this link: https://cloud.google.com/dialogflow/docs/quick/api#detect-intent-text-csharp

Then I made this code:

...

// 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);

...

I've found when looking at the Debug - Output while in debugging mode the Output prints this after / while it hangs:

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

Execution just hangs on that last line .DetectIntent.

Where am I going wrong?

Any help / advice will be appreciated.

1
What error are you getting ? Are you authenticating successfully ? - Marc Asmar
No error. It just hangs on that line: ...mainSessionsClient.DetectIntent(... - Shiasu-sama
The line: SessionsClient mainSessionsClient = SessionsClient.Create(mainChannel); runs fine. So I assume I'm authenticating successfully. Is there maybe another way I can check / test if I'm authenticating correctly? - Shiasu-sama
Check my answer here: stackoverflow.com/a/58447825/9888221 That code is tested and still working perfectly, hopefully that can help a bit - Marc Asmar
I am using Google.Cloud.Dialogflow.V2 ( 1.0.0 ) which has Grpc.Core (1.22.0) - Marc Asmar

1 Answers

3
votes

I found the problem:

The problem was the versions of the packages I had installed were not properly compatible I guess.

My Grpc.Core was on (v1.22.1) but my Grpc.Core.Api was on (v2.26.0). When I changed my Grpc.Core.Api version to (v1.22.1) and tried again; my system did not hang anymore and I got a response. I also did not get the Debug Output print of: Exception thrown: 'System.MissingMethodException' in Grpc.Core.dll anymore.

Thanks to Marc Asmar for your helpful comments and links.