dotnet / dotnet/aspnetcore

AddStackExchangeRedis doesn't read Aspire connection string

Open
#62,543 4 comments 0 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] 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

```cs
var builder = DistributedApplication.CreateBuilder(args);
var redis = builder.AddRedis("redis-cache");
builder.AddProject("blazorsingalrapp1")
.WithReference(redis);

builder.Build().Run();
```

And here's how the API service (BlazorSingalRApp1) project's program.cs is configured
```cs
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.