{"record":{"id":"6dd80c9770f4eb77","repo":"microsoft/aspire","slug":"resource-resource-name-stopped-waiting-for-dependency-6dd80c","errorCode":null,"errorMessage":"Resource '{resource.Name}' stopped waiting for dependency resource '{displayName}' because it entered the '{snapshot.State.Text}' state with exit code '{snapshot.ExitCode}', expected '{exitCode}'.","messagePattern":"Resource '(.+?)' stopped waiting for dependency resource '(.+?)' because it entered the '(.+?)' state with exit code '(.+?)', expected '(.+?)'\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs","lineNumber":354,"sourceCode":"            {\n                resourceLogger.LogError(\n                    \"Dependency resource '{ResourceName}' failed to start.\",\n                    displayName\n                    );\n\n                throw new DistributedApplicationException($\"Resource '{resource.Name}' stopped waiting for dependency resource '{displayName}' because it failed to start.\");\n            }\n            else if ((snapshot.State!.Text == KnownResourceStates.Finished || snapshot.State!.Text == KnownResourceStates.Exited) && snapshot.ExitCode is not null && snapshot.ExitCode != exitCode)\n            {\n                resourceLogger.LogError(\n                    \"Resource '{ResourceName}' has entered the '{State}' state with exit code '{ExitCode}' expected '{ExpectedExitCode}'.\",\n                    displayName,\n                    snapshot.State.Text,\n                    snapshot.ExitCode,\n                    exitCode\n                    );\n\n                throw new DistributedApplicationException(\n                    $\"Resource '{resource.Name}' stopped waiting for dependency resource '{displayName}' because it entered the '{snapshot.State.Text}' state with exit code '{snapshot.ExitCode}', expected '{exitCode}'.\"\n                    );\n            }\n\n            resourceLogger.LogInformation(\"Finished waiting for resource '{ResourceName}'.\", displayName);\n\n            if (onDependencyReady is not null)\n            {\n                await onDependencyReady(resourceId).ConfigureAwait(false);\n            }\n\n            static bool IsKnownTerminalState(CustomResourceSnapshot snapshot) =>\n                KnownResourceStates.TerminalStates.Contains(snapshot.State?.Text) ||\n                snapshot.ExitCode is not null;\n        }\n    }\n\n    private async Task WaitUntilStateAsync(IResource resource, IResource dependency, WaitBehavior waitBehavior,","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs#L336-L372","documentation":"Thrown by WaitUntilCompletionAsync when the dependency resource terminates (Finished/Exited) but its exit code differs from the expected exit code passed to WaitForCompletion. Aspire stops waiting because the completion condition can never be satisfied.","triggerScenarios":"resource.WaitForCompletion(name, exitCode: N) where the dependency process exits with a code other than N (commonly a nonzero crash code).","commonSituations":"A migration or seeding job crashes with a nonzero exit code; the expected exit code assumption changed (tool now returns 0 or a different sentinel code); dependency fails due to bad arguments or DB connection errors.","solutions":["Read the dependency's exit code from the error message and its logs to diagnose why it exited abnormally.","Correct the dependency's failure (args, connection string, environment).","If the new exit code is legitimate, update the expected exitCode argument to match.","If any nonzero code indicates failure and any zero means success, keep WaitForCompletion with the standard 0 expectation and fix the root cause."],"exampleFix":"// before\nbuilder.AddProject<Projects.Api>(\"api\")\n    .WaitForCompletion(\"migrator\", exitCode: 0); // migrator exits 2\n\n// after: fix the migrator (e.g. correct connection string) or accept its real success code\nbuilder.AddProject<Projects.Api>(\"api\")\n    .WaitForCompletion(\"migrator\", exitCode: 2); // only if 2 is now the documented success code","handlingStrategy":"validation","validationCode":"// Run the job once manually and confirm its success exit code matches the expectation\n// var expectedExitCode = 0; // verify with: dotnet run --project migrator; echo $?","typeGuard":null,"tryCatchPattern":"try\n{\n    await app.StartAsync();\n}\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"exit code\"))\n{\n    logger.LogError(ex, \"Dependency exited with an unexpected exit code.\");\n}","preventionTips":["Verify the job's documented success exit code before hardcoding exitCode in WaitForCompletion.","Diagnose nonzero exit codes from dependency logs before changing expectations.","Keep jobs deterministic: validate connection strings and args before run.","Avoid swallowing exit-code mismatches; they usually indicate a real job failure."],"tags":["aspire","dependency","exit-code","wait-for-completion"],"backgroundTag":"unexpected-exit-code","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}