microsoft/aspire · error · InvalidOperationException
Named service references are not supported for Azure…
Error message
Named service references are not supported for Azure Functions resources.
What it means
TryWithReference in the Azure Functions extensions rejects named service references: when a non-null name is supplied along with the reference, it throws this InvalidOperationException. Functions projects derive their config keys from the referenced resource, and custom names would break that mapping.
Solutions
- Drop the name argument and call the unnamed WithReference overload; Functions derives the config key automatically.
- If a specific name is required, create a wrapper resource or use environment variables directly via WithEnvironment.
- Adjust shared wiring helpers to not pass names for Functions destinations.
Example fix
// before functionsProject.WithReference(cache, "RedisConnection"); // after functionsProject.WithReference(cache); // key is derived from the resource
Defensive patterns
Strategy: validation
Validate before calling
if (name is not null && destination.Resource is AzureFunctionsProjectResource) throw new InvalidOperationException("Do not pass a connection name to WithReference on Azure Functions resources."); Type guard
static bool SupportsNamedReference(IResourceBuilder<IResource> b) => b.Resource is not AzureFunctionsProjectResource;
Try / catch
try { functionsProject.WithReference(dep, "MyConn"); } catch (InvalidOperationException ex) when (ex.Message.Contains("Named service references")) { /* retry without name */ } Prevention
- Use the unnamed WithReference overload for Functions projects.
- Let Functions derive config keys from the resource name.
- Audit shared helper methods for name arguments.
When it happens
Trigger: Calling WithReference(destination, source, connectionName: "myname") (or equivalent named overload) on an Azure Functions project resource.
Common situations: Providing an explicit connection/environment-variable name as you would for a normal project; migrating reference code from a WebApp to a Functions app while keeping the name argument.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Optional references are not supported for Azure Functions…
- Endpoint references do not support connectionName…
- Named service references are only supported for resources…
- Optional references are only supported for connection…
- Reference names are not supported for external services.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/080e7154a6071144.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Functions/AzureFunctionsProjectResourceExtensions.cs:376
IResourceBuilder<AzureFunctionsProjectResource> destination,
IResourceBuilder<IResource> source,
string? connectionName,
bool optional,
string? name)
{
if (source.Resource is not IResourceWithConnectionString || source.Resource is not IResourceWithAzureFunctionsConfig azureFunctionsConfig)
{
return null;
}
if (optional)
{
throw new InvalidOperationException("Optional references are not supported for Azure Functions resources.");
}
if (name is not null)
{
throw new InvalidOperationException("Named service references are not supported for Azure Functions resources.");
}
destination.WithReferenceRelationship(source.Resource);
return destination.WithEnvironment(context =>
{
connectionName ??= source.Resource.Name;
azureFunctionsConfig.ApplyAzureFunctionsConfiguration(context.EnvironmentVariables, connectionName);
});
}
private static string CreateDefaultStorageName(this IDistributedApplicationBuilder builder)
{
// Use ProjectNameSha256 for stable naming across deployments regardless of path
var applicationHash = builder.Configuration["AppHost:ProjectNameSha256"]![..5].ToLowerInvariant();
return $"{DefaultAzureFunctionsHostStorageName}{applicationHash}";
}
View on GitHub (pinned to 25830f84bd)