microsoft / vs-dapr

View, manage, and diagnose Dapr services within Visual Studio.
https://dapr.io
MIT License
21 stars 2 forks source link

Unable to Debug Application #17

Closed rpersent closed 6 months ago

rpersent commented 6 months ago

Hi, I have installed the extension with the following configuration:

apps:
- appDirPath: DaprStateWorker
  command:
  - dotnet
  - run
version: 1

My statestore is the default redis store

My application is a default worker project and this is my code:

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
    while (!stoppingToken.IsCancellationRequested)
    {
        if (_logger.IsEnabled(LogLevel.Information))
        {
            _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
        }

        var key = Guid.NewGuid().ToString();

        string DAPR_STORE_NAME = "statestore";
        using var client = new DaprClientBuilder().Build();
        await client.SaveStateAsync(DAPR_STORE_NAME, key, "testing");
        var result = await client.GetStateAsync<string>(DAPR_STORE_NAME, key);
        Console.WriteLine($"Result after get {result}");
        Console.ReadLine();

        await Task.Delay(2000, stoppingToken);
    }
}

When I debug, I hit my breakpoint, but as soon as it attempts to save state I get the following error:

fail: Microsoft.Extensions.Hosting.Internal.Host[9]
      BackgroundService failed
      Dapr.DaprException: State operation failed: the Dapr endpoint indicated a failure. See InnerException for details.       ---> Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="Error connecting to subchannel.", DebugException="System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.")       ---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
         at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
         at Grpc.Net.Client.Balancer.Internal.SocketConnectivitySubchannelTransport.TryConnectAsync(ConnectContext context)
         --- End of inner exception stack trace ---
         at Grpc.Net.Client.Balancer.Internal.ConnectionManager.PickAsync(PickContext context, Boolean waitForReady, CancellationToken cancellationToken)
         at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
         at System.Net.Http.HttpMessageInvoker.<SendAsync>g__SendAsyncWithTelemetry|6_0(HttpMessageHandler handler, HttpRequestMessage request, CancellationToken cancellationToken)
         at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)
         at Dapr.Client.DaprClientGrpc.MakeSaveStateCallAsync[TValue](String storeName, String key, TValue value, String etag, StateOptions stateOptions, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at Dapr.Client.DaprClientGrpc.MakeSaveStateCallAsync[TValue](String storeName, String key, TValue value, String etag, StateOptions stateOptions, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
         at Dapr.Client.DaprClientGrpc.SaveStateAsync[TValue](String storeName, String key, TValue value, StateOptions stateOptions, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
         at DaprStateWorker.Worker.ExecuteAsync(CancellationToken stoppingToken) in C:\dev\playground\DaprState\DaprStateWorker\Worker.cs:line 27
         at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)
crit: Microsoft.Extensions.Hosting.Internal.Host[10]
      The HostOptions.BackgroundServiceExceptionBehavior is configured to StopHost. A BackgroundService has thrown an unhandled exception, and the IHost instance is stopping. To avoid this behavior, configure this to Ignore; however the BackgroundService will not be restarted.
      Dapr.DaprException: State operation failed: the Dapr endpoint indicated a failure. See InnerException for details.       ---> Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="Error connecting to subchannel.", DebugException="System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.")       ---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
         at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
         at Grpc.Net.Client.Balancer.Internal.SocketConnectivitySubchannelTransport.TryConnectAsync(ConnectContext context)
         --- End of inner exception stack trace ---
         at Grpc.Net.Client.Balancer.Internal.ConnectionManager.PickAsync(PickContext context, Boolean waitForReady, CancellationToken cancellationToken)
         at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
         at System.Net.Http.HttpMessageInvoker.<SendAsync>g__SendAsyncWithTelemetry|6_0(HttpMessageHandler handler, HttpRequestMessage request, CancellationToken cancellationToken)
         at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)
         at Dapr.Client.DaprClientGrpc.MakeSaveStateCallAsync[TValue](String storeName, String key, TValue value, String etag, StateOptions stateOptions, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at Dapr.Client.DaprClientGrpc.MakeSaveStateCallAsync[TValue](String storeName, String key, TValue value, String etag, StateOptions stateOptions, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
         at Dapr.Client.DaprClientGrpc.SaveStateAsync[TValue](String storeName, String key, TValue value, StateOptions stateOptions, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
         at DaprStateWorker.Worker.ExecuteAsync(CancellationToken stoppingToken) in C:\dev\playground\DaprState\DaprStateWorker\Worker.cs:line 27
         at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)

The Dapr window says No Dapr applications are running.

When run using the dapr run command dapr run --app-id demo dotnet run I can see the application in the Dapr window and I can attach to the process and debug.

philliphoff commented 6 months ago

@rpersent In VS, with your solution open, you should see a "Dapr" project node in Solution Explorer (by virtual of having a Dapr run file in the solution folder). Make sure that that project is the "active" project before you F5. It looks like the worker project may be the active project, in which case the sidecar will not have been started.

rpersent commented 6 months ago

@philliphoff thank, that has worked