microsoft/aspire · error · DistributedApplicationException
Project metadata was not found for resource
Error message
Project metadata was not found for resource '{project.Name}'. What it means
During manifest publishing, ManifestPublishingContext.WriteProjectAsync serializes a ProjectResource, but every project resource must carry IProjectMetadata (its project file path). If the resource is a ProjectResource without that metadata annotation, Aspire cannot emit a valid manifest entry, so it throws DistributedApplicationException. This is an internal model invariant: only AddProject creates valid project resources.
Solutions
- Use IDistributedApplicationBuilder.AddProject<TProject>(name) instead of manually constructing ProjectResource so IProjectMetadata is attached automatically.
- If building a custom resource, ensure TryGetProjectMetadata succeeds by annotating the resource with IProjectMetadata (project path resolved via PhysicalFile path of the .csproj).
- Check custom model transforms/annotations that may remove project metadata before publishing.
Example fix
// before
var project = new ProjectResource("api");
builder.AddResource(project);
// after
builder.AddProject<Projects.Api>("api"); Defensive patterns
Strategy: validation
Validate before calling
if (!project.TryGetProjectMetadata(out var metadata))
{
throw new InvalidOperationException($"Resource '{project.Name}' is a ProjectResource without project metadata; use AddProject<T>.");
} Type guard
static bool HasProjectMetadata(ProjectResource p) => p.TryGetProjectMetadata(out _);
Prevention
- Always create project resources via AddProject<TProject>.
- Never construct ProjectResource manually in production code.
- Review custom model transforms for annotation removal.
When it happens
Trigger: Calling AddResource (or building a custom resource derived from ProjectResource) with a ProjectResource constructed manually that never received IProjectMetadata, instead of using builder.AddProject; or removing/replacing the metadata annotation before publish runs.
Common situations: Custom resource-building helpers that new up ProjectResource directly; tests or tools that manipulate the distributed application model and strip annotations; upgrading custom code after the ProjectResource/metadata API changed.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Could not get directory name of output path
- Could not get the container image name for resource
- The '--output-path [path]' option was not specified even…
- The '--output-path [path]' option was not specified even…
- A ConfigureRadiusInfrastructure callback removed or…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/196912c8d4270dc9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs:179
{
Writer.WriteString("error", "This resource does not support generation in the manifest.");
return Task.CompletedTask;
}
private Task WriteConnectionStringAsync(IResourceWithConnectionString resource)
{
// Write connection strings as value.v0
Writer.WriteString("type", "value.v0");
WriteConnectionString(resource);
return Task.CompletedTask;
}
private async Task WriteProjectAsync(ProjectResource project)
{
if (!project.TryGetProjectMetadata(out var metadata))
{
throw new DistributedApplicationException($"Project metadata was not found for resource '{project.Name}'.");
}
var relativePathToProjectFile = GetManifestRelativePath(metadata.ProjectPath);
var deploymentTarget = project.GetDeploymentTargetAnnotation();
if (deploymentTarget is not null)
{
Writer.WriteString("type", "project.v1");
}
else
{
Writer.WriteString("type", "project.v0");
}
Writer.WriteString("path", relativePathToProjectFile);
if (deploymentTarget is not null)
{View on GitHub (pinned to 25830f84bd)