Skip to content

AddStackExchangeRedis doesn't read Aspire connection string #62543

@dart1235

Description

@dart1235

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm using AddStackExchangeRedis() method to setup SignalR's Redis backplane. However, the API service can't connect to the Redis instance.

Here's the code from AppHost's Program.cs

var builder = DistributedApplication.CreateBuilder(args);
var redis = builder.AddRedis("redis-cache");
builder.AddProject<Projects.BlazorSingalRApp1>("blazorsingalrapp1")
    .WithReference(redis);

builder.Build().Run();

And here's how the API service (BlazorSingalRApp1) project's program.cs is configured

builder.Services.AddSignalR()
    .AddStackExchangeRedis("redis-cache", options =>
    {
        options.Configuration.ChannelPrefix = "MyApp";
        options.Configuration.AbortOnConnectFail = false;
    });

However, when I run the apphost, the backend API service can't connect and the logs show

fail: Microsoft.AspNetCore.SignalR.StackExchangeRedis.RedisHubLifetimeManager[7] Not connected to Redis.
StackExchange.Redis.RedisConnectionException: UnableToConnect on redis-cache:6379/Subscription

It appears that maybe AddStackExchangeRedis call doesn't honor the connection string coming from Aspire because at runtime config.GetConnectionString("redis-cache") has the right connection string.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version info

9.0

Anything else?

Aspire 9.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions