microsoft / microsoft/aspire

Tests can require you to create `DcpOptions` to resolve environment variables

Open
#14,831 1 comment 0 reactions 0 assignees View on GitHub
area-app-testing
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

While upgrading the Community Toolkit to 13.2 I hit this error: https://github.com/CommunityToolkit/Aspire/actions/runs/22473608048/job/65095823926?pr=1130#step:6:75

The initial problem is that the tests didn't have an `IServiceProvider` configured, resulting in:

```
System.InvalidOperationException
HResult=0x80131509
Message=IServiceProvider is not available because the container has not yet been built.
Source=Aspire.Hosting
StackTrace:
at Aspire.Hosting.DistributedApplicationExecutionContext.get_ServiceProvider() in /_/src/Aspire.Hosting/DistributedApplicationExecutionContext.cs:line 73
```

If you provide a service provider (say, from the app that gets built from the app host) you get this error:

```
Microsoft.Extensions.Options.OptionsValidationException
HResult=0x80131500
Message=Property CliPath: The path to the DCP executable used for Aspire orchestration is required.; Property DashboardPath: The path to the Aspire Dashboard binaries is missing.
Source=Microsoft.Extensions.Options
StackTrace:
at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
```

That is raised from the constructor of `DcpDependencyCheck`.

### Expected Behavior

Test shouldn't require me to create an internal type.

### Steps To Reproduce

Here's a test that will fail:

```csharp
var appBuilder = DistributedApplication.CreateBuilder();

var surrealServer = appBuilder
.AddContainer("container", "ubuntu")
.WithOtlpExporter();

using var app = appBuilder.Build();

// Verify that OtlpExporterAnnotation is present (added by WithOtlpExporter)
// This annotation marks the resource as an OTEL exporter
Assert.True(surrealServer.Resource.HasAnnotationOfType());

var variables = await surrealServer.Resource.GetEnvironmentVariablesAsync(serviceProvider: app.Services);

bool hasValue = variables.TryGetValue("SURREAL_TELEMETRY_PROVIDER", out var value);

Assert.True(hasValue);
Assert.Equal("otlp", value);
```

### Exceptions (if any)

_No response_

### .NET Version info

_No response_

### Anything else?

_No response_

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.