microsoft/aspire · error · InvalidOperationException
Value for provider has not been set.
Error message
Value for provider has not been set.
What it means
GetValueAsync on a Foundry hosted agent value provider throws InvalidOperationException when Set was never called (_isSet is false). The provider is intentionally write-once/read-after-write, so reading before assignment is a programming error rather than a null return.
Solutions
- Ensure Set is called before any GetValueAsync call
- Check ordering: wait for the provisioning/configuration phase that assigns provider values before reading
- Verify all code paths that create the provider also call Set on it
- If unset is legitimate, restructure to use a nullable holder instead of this provider
Example fix
// before var value = await provider.GetValueAsync(); // throws: never set // after if (!isConfigured) provider.Set(defaultValue); var value = await provider.GetValueAsync();
Defensive patterns
Strategy: try-catch
Validate before calling
// No public IsSet property; wrap reads
async Task<string?> SafeGetAsync(Provider p, CancellationToken ct)
{
try { return await p.GetValueAsync(ct); }
catch (InvalidOperationException) { return null; }
} Try / catch
string? value;
try
{
value = await provider.GetValueAsync(ct);
}
catch (InvalidOperationException ex) when (ex.Message == "Value for provider has not been set.")
{
logger.LogError(ex, "Provider read before configuration completed.");
throw;
} Prevention
- Only read provider values after the provisioning/configuration phase completes
- Ensure every code path that creates a provider also calls Set
- Sequence GetValueAsync calls after Set in tests and startup code
When it happens
Trigger: Calling GetValueAsync before the framework (or your code) has called Set — e.g. reading the value before provisioning/config resolution completes, or a code path that conditionally skips Set.
Common situations: Reading the value too early in the application lifecycle (before the value resolution phase); a conditional branch that fails to call Set; test that reads an unconfigured provider.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Value has already been set.
- AppHost:DeploymentStatePathSha256 is required to isolate…
- Azure AI Search tool
- Azure AI Search tool
- AzureEnvironmentResource must be present in the application…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/56550820b0380276.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Foundry/HostedAgent/AzureHostedAgentResource.cs:552
{
_isSet = false;
}
/// <summary>
/// Creates a new instance of the <see cref="StaticValueProvider{T}"/> class.
/// </summary>
public StaticValueProvider(T value)
{
_value = value;
_isSet = true;
}
/// <inheritdoc/>
public ValueTask<string?> GetValueAsync(CancellationToken cancellationToken = default)
{
if (_isSet == false)
{
throw new InvalidOperationException("Value for provider has not been set.");
}
else
{
return ValueTask.FromResult(_value?.ToString());
}
}
}
View on GitHub (pinned to 25830f84bd)