-
Notifications
You must be signed in to change notification settings - Fork 695
Closed
Copy link
Labels
area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication‼️regression-from-last-releaseThis used to work in an earlier version of Aspire and we broke it!This used to work in an earlier version of Aspire and we broke it!
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
After upgrading an app to 9.2 (Version: 9.2.0-preview.1.25205.2 specifically) one resource failed to start up with the error Failed to apply environment variable 'ConnectionStrings__NAME'. A dependency may have failed to start
I have been able to reduce this down to the below minimal repo.
Curiously even though the executable and container dependencies reference the original resoruce the same way, this error only affects the container resource - the executable finds the connection string just fine.
Expected Behavior
As the resources all started on 9.1, they should continue to start on 9.2
Steps To Reproduce
Run the followign on 9.1 and 9.2
var builder = DistributedApplication.CreateBuilder(args);
var connectionStringResource = builder.AddResource(new MyContainerResource("myContainer"))
.WithImage("redis")
.WithHttpEndpoint(targetPort: 8080);
var executableDependency = builder.AddExecutable("executableDependency", "pwsh", ".")
.WithReference(connectionStringResource)
.WaitFor(connectionStringResource);
var containerDependnecy = builder.AddContainer("containerDependnecy", "redis")
.WithReference(connectionStringResource)
.WaitFor(connectionStringResource);
builder.Build().Run();
public class MyContainerResource : ContainerResource, IResourceWithConnectionString
{
public MyContainerResource(string name) : base(name)
{
PrimaryEndpoint = new(this, "http");
}
public EndpointReference PrimaryEndpoint { get; }
public ReferenceExpression ConnectionStringExpression =>
ReferenceExpression.Create($"{PrimaryEndpoint.Property(EndpointProperty.Url)}");
}
Exceptions (if any)
Waiting for resource 'myContainer' to enter the 'Running' state.
Waiting for resource ready to execute for 'myContainer'.
Finished waiting for resource 'myContainer'.
Failed to apply environment variable 'ConnectionStrings__myContainer'. A dependency may have failed to start.
Aspire.Hosting.DistributedApplicationException: The connection string for the resource 'myContainer' is not available.
at Aspire.Hosting.ApplicationModel.ConnectionStringReference.ThrowConnectionStringUnavailableException() in /_/src/Aspire.Hosting/ApplicationModel/ConnectionStringReference.cs:line 36
at Aspire.Hosting.ApplicationModel.ExpressionResolver.ResolveConnectionStringReferenceAsync(ConnectionStringReference cs) in /_/src/Aspire.Hosting/ApplicationModel/ExpressionResolver.cs:line 163
at Aspire.Hosting.ApplicationModel.ExpressionResolver.ResolveInternalAsync(Object value) in /_/src/Aspire.Hosting/ApplicationModel/ExpressionResolver.cs:line 174
at Aspire.Hosting.ApplicationModel.ExpressionResolver.ResolveWithContainerSourceAsync(IValueProvider valueProvider, String containerHostName, Boolean sourceIsContainer, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/ApplicationModel/ExpressionResolver.cs:line 192
at Aspire.Hosting.ApplicationModel.ExpressionResolver.ResolveAsync(Boolean sourceIsContainer, IValueProvider valueProvider, String containerHostName, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/ApplicationModel/ExpressionResolver.cs:line 200
at Aspire.Hosting.ApplicationModel.ResourceExtensions.GetValue(String key, IValueProvider valueProvider, ILogger logger, Boolean isContainer, String containerHostName, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs:line 463
at Aspire.Hosting.ApplicationModel.ResourceExtensions.ProcessEnvironmentVariableValuesAsync(IResource resource, DistributedApplicationExecutionContext executionContext, Action`4 processValue, ILogger logger, String containerHostName, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs:line 361
.NET Version info
No response
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication‼️regression-from-last-releaseThis used to work in an earlier version of Aspire and we broke it!This used to work in an earlier version of Aspire and we broke it!