Thomas
Thomas

Reputation: 2116

Google Cloud Vision API - Error creating Grpc.Core.Channel

I am trying to use Google Cloud Vision V1 Api's ImageAnnotatorClient class. I am following the example at https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Vision.V1/api/Google.Cloud.Vision.V1.ImageAnnotatorClient.html under the

Create(ServiceEndpoint, ImageAnnotatorSettings)

header. I am using C# and trying to build a classic console application. I am using GRPC.Core version 1.15.0, and Google.Cloud.Vision.V1 version 1.2.0 from Nuget. I get a compile error

'GoogleCredential' does not contain a definition for 'ToChannelCredentials' and no extension method 'ToChannelCredentials' accepting a first argument of type 'GoogleCredential' could be found

The below is my code:

GoogleCredential credential = GoogleCredential
    .FromFile(@"C:\Users\...\12345.json")
    .CreateScoped(ImageAnnotatorClient.DefaultScopes);
            Google.Cloud.Vision.V1.Image image1 = Google.Cloud.Vision.V1.Image.FromFile(@"c:\Users\....\Image14b.png");

            Channel channel = new Channel(
    ImageAnnotatorClient.DefaultEndpoint.Host, ImageAnnotatorClient.DefaultEndpoint.Port, credential.ToChannelCredentials());
            ImageAnnotatorClient client = ImageAnnotatorClient.Create(channel);

            IReadOnlyList<EntityAnnotation> textAnnotations = client.DetectText(image1);

I get error at the line below:

        Channel channel = new Channel(
ImageAnnotatorClient.DefaultEndpoint.Host, ImageAnnotatorClient.DefaultEndpoint.Port, credential.ToChannelCredentials());

Any hints please?

Upvotes: 0

Views: 1081

Answers (1)

Amanda Tarafa Mas
Amanda Tarafa Mas

Reputation: 1128

You might be missing one of the using directives, specifically

using Grpc.Auth;

See here the definition of ToChannelCredentials as an extension method.

Check that you have included all the other using directives present in the sample as well.

Upvotes: 5

Related Questions