I am seeing a weird scenario while using DAPR in c# console application. I have create a console app and running as a cron job in Kubernetes. The code is supposed to publish a message to Azure service bus queue . I am using a DAPR sidecar. The issue I am facing is what when I try to publish message from Main body, it works fine but when I publish it from a separate method I get DaprException . Below is the code:
static async Task Main(string[] args)
{
using (var client = new DaprClientBuilder().Build())
{
string topicName = "topic1";
await client.PublishEventAsync("pubsub", topicName, "testdapr2");
Console.WriteLine("Message published successfully.");
}
await PublishMessage();
}
private static async Task PublishMessage()
{
Console.WriteLine("Getting Error");
using (var client = new DaprClientBuilder().Build())
{
string topicName = "topic1";
await client.PublishEventAsync("pubsub", topicName, "testdapr2");
Console.WriteLine("Message published successfully.");
}
}
The DAPR publish in Main works fine but when I try to publish message in "PublishMessage()" I am getting below error:
DaprException: Publish 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|281_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 Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)
at Dapr.Client.DaprClientGrpc.MakePublishRequest(String pubsubName, String topicName, ByteString content, Dictionary`2 metadata, String dataContentType, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
Please suggest if anyone have faces this error.



