microsoft/aspire · error · InvalidOperationException

Resource ' ' has a parent process persistence mode but no…

Error message

Resource '{resource.Name}' has a parent process persistence mode but no parent process identity.

What it means

For PersistenceMode.ParentProcess, the annotation must carry both ParentProcessId and ParentProcessTimestamp so the runtime can track the owning process. If the mode is ParentProcess but either identity value is missing, TryGetParentProcessLifetime throws InvalidOperationException.

Solutions

  1. Set both ParentProcessId and ParentProcessTimestamp on the annotation when using ParentProcess mode.
  2. Use a different PersistenceMode (Session/Persistent/Resource) if parent process tracking is not intended.
  3. Verify annotations built programmatically include the full parent process identity.

Example fix

// before
new PersistenceAnnotation { Mode = PersistenceMode.ParentProcess }; // missing identity
// after
new PersistenceAnnotation { Mode = PersistenceMode.ParentProcess, ParentProcessId = pid, ParentProcessTimestamp = timestamp };
Defensive patterns

Strategy: validation

Validate before calling

if (pa.Mode == PersistenceMode.ParentProcess && (pa.ParentProcessId is null || pa.ParentProcessTimestamp is null)) throw new InvalidOperationException("ParentProcess mode requires ParentProcessId and ParentProcessTimestamp");

Type guard

bool HasParentIdentity(PersistenceAnnotation pa) => pa.Mode != PersistenceMode.ParentProcess || (pa.ParentProcessId is not null && pa.ParentProcessTimestamp is not null);

Try / catch

try { resource.TryGetParentProcessLifetime(out var pid, out var ts); } catch (InvalidOperationException ex) when (ex.Message.Contains("no parent process identity")) { /* complete annotation identity */ throw; }

Prevention

When it happens

Trigger: Constructing a PersistenceAnnotation with Mode = ParentProcess without setting ParentProcessId or ParentProcessTimestamp, then resolving the resource's parent process lifetime.

Common situations: Custom annotation construction that sets the mode but forgets the identity fields; APIs or tooling that copy a persistence annotation while dropping the parent process metadata.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/e8d524ad20e60ac9. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs:1190

    }

    private static bool TryGetParentProcessLifetime(IResource resource, HashSet<IResource> visitedResources, out int parentProcessId, out DateTime parentProcessTimestamp)
    {
        if (!visitedResources.Add(resource))
        {
            throw new InvalidOperationException($"A circular lifetime reference was detected for resource '{resource.Name}'.");
        }

        if (resource.TryGetLastAnnotation<PersistenceAnnotation>(out var persistenceAnnotation))
        {
            switch (persistenceAnnotation.Mode)
            {
                case PersistenceMode.ParentProcess when persistenceAnnotation.ParentProcessId is { } id && persistenceAnnotation.ParentProcessTimestamp is { } timestamp:
                    parentProcessId = id;
                    parentProcessTimestamp = timestamp;
                    return true;
                case PersistenceMode.ParentProcess:
                    throw new InvalidOperationException($"Resource '{resource.Name}' has a parent process persistence mode but no parent process identity.");
                case PersistenceMode.Resource:
                    return persistenceAnnotation.SourceResource is { } sourceResource
                        ? TryGetParentProcessLifetime(sourceResource, visitedResources, out parentProcessId, out parentProcessTimestamp)
                        : throw new InvalidOperationException($"Resource '{resource.Name}' has a resource persistence mode but no source resource.");
                case PersistenceMode.Session or PersistenceMode.Persistent:
                    parentProcessId = 0;
                    parentProcessTimestamp = default;
                    return false;
            }
        }

        parentProcessId = 0;
        parentProcessTimestamp = default;
        return false;
    }

    /// <summary>
    /// Determines whether the specified resource has a pull policy annotation and retrieves the value if it does.

View on GitHub (pinned to 25830f84bd)