Asp.net Core .net 6 Grpc Exception

Hi, I am having an issue to execute a command on Asp.net core .net 6. Thanks

What Dgraph client (and version) are you using?

(put “x” in the box to select)

Version: 21.3.1.2

What version of Dgraph are you using?

v21.03.2

What is the hardware spec (RAM, OS)?

16gb RAM, Mac OS

Steps to reproduce the issue (command/config used to run Dgraph).

c# code as follows

  try
        {
            var query2 = @"query {  qry(func: type(ApiController)){
                                Id: uid,
                                Name: ApiC_Name,
                                Key: ApiC_Key
                              }}";

            1
            var grpcChannel = GrpcChannel.ForAddress("http://localhost:9080", new GrpcChannelOptions()
            {
                LoggerFactory = _loggerFactory
            });

            var dgraphClient = new DgraphClient(grpcChannel);

            var rs = dgraphClient.NewTransaction().Query(query2).Result;

            System.Diagnostics.Debugger.Break();
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debugger.Break();
        }

The code above using .Net 6 on Mac OS Big Sur version 11.6

  1. On Console App .net 6 works no issue only by installing nuget Grpc.Net.Client version 2.4.0.0
  2. On Asp.Net Core .net 6 have the following exception
    Status(StatusCode=Internal, Detail=“Error starting gRPC call: An error occurred while sending the request.”)

From the logs i got:

e[40me[37mdbuge[39me[22me[49m: Grpc.Net.Client.Internal.GrpcCall[1]
Starting gRPC call. Method type: ‘Unary’, URI: ‘http://localhost:9080/api.Dgraph/Query’.
Grpc.Net.Client.Internal.GrpcCall: Debug: Starting gRPC call. Method type: ‘Unary’, URI: ‘http://localhost:9080/api.Dgraph/Query’.
e[40me[37mdbuge[39me[22me[49m: Grpc.Net.Client.Internal.GrpcCall[18]
Sending message.
Grpc.Net.Client.Internal.GrpcCall: Debug: Sending message.
e[41me[30mfaile[39me[22me[49m: Grpc.Net.Client.Internal.GrpcCall[6]
Error starting gRPC call.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
—> System.IO.IOException: The response ended prematurely.
at System.Net.Http.HttpConnection.FillAsync(Boolean async)
at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean async, Boolean foldedHeadersAllowed)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
— End of inner exception stack trace —
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendUsingHttp11Async(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.DetermineVersionAndSendAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendAndProcessAltSvcAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request)
Grpc.Net.Client.Internal.GrpcCall: Error: Error starting gRPC call.

System.Net.Http.HttpRequestException: An error occurred while sending the request.
—> System.IO.IOException: The response ended prematurely.
at System.Net.Http.HttpConnection.FillAsync(Boolean async)
at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean async, Boolean foldedHeadersAllowed)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
— End of inner exception stack trace —
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendUsingHttp11Async(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.DetermineVersionAndSendAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendAndProcessAltSvcAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request)
e[40me[37mdbuge[39me[22me[49m: Grpc.Net.Client.Internal.GrpcCall[8]
gRPC call canceled.
Grpc.Net.Client.Internal.GrpcCall: Debug: gRPC call canceled.
e[41me[30mfaile[39me[22me[49m: Grpc.Net.Client.Internal.GrpcCall[3]
Call failed with gRPC error status. Status code: ‘Internal’, Message: ‘Error starting gRPC call: An error occurred while sending the request.’.
Grpc.Net.Client.Internal.GrpcCall: Error: Call failed with gRPC error status. Status code: ‘Internal’, Message: ‘Error starting gRPC call: An error occurred while sending the request.’.
e[40me[37mdbuge[39me[22me[49m: Grpc.Net.Client.Internal.GrpcCall[4]
Finished gRPC call.
Grpc.Net.Client.Internal.GrpcCall: Debug: Finished gRPC call.

Make a question in Stackoverflow too. We don’t have too many .NET devs in the community and that feels something related to gRPC. Maybe searching for the gRPC error code might help.

I’ll try to find someone to help you(no promises that I’ll find :P)

Cheers.

Is the Dgraph cluster accessible via localhost:9080? Are you able to successfully connect via Ratel or a different client? It sounds like Dgraph isn’t running that’s causing the connection error that you’re seeing.

Hi, thanks for the response.

Yes everything regarding accessibility is working since i created two projects to test, one Console Application that works without problem and one Asp.net code that did not work.

Hi, thanks for the response.

As you said it is related to gRPC and i think it is also related to MAC.

I have followed this article

And somehow made it work by trial and errors.

GrpcChannel.ForAddress("http://localhost:9080".
??? try GrpcChannel.ForAddress("localhost:9080"