{"record":{"id":"93a1cbfd7e054920","repo":"microsoft/aspire","slug":"developer-control-plane-dcp-exited-before-writing-kubeconfig","errorCode":null,"errorMessage":"Developer Control Plane (DCP) exited before writing kubeconfig. Exit code: {0}.{1}{2}.","messagePattern":"Developer Control Plane \\(DCP\\) exited before writing kubeconfig\\. Exit code: (.+?)\\.(.+?)(.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Utils/EnvironmentChecker/DcpConnectionChecker.cs","lineNumber":387,"sourceCode":"\n                try\n                {\n                    Directory.Delete(_sessionDirectory, recursive: true);\n                }\n                catch (Exception ex)\n                {\n                    _logger.LogDebug(ex, \"Failed to delete DCP doctor session directory '{SessionDirectory}'.\", _sessionDirectory);\n                }\n            }\n        }\n\n        private async Task WaitForKubeconfigFileAsync(CancellationToken cancellationToken)\n        {\n            while (!File.Exists(_kubeconfigPath))\n            {\n                if (_process.HasExited)\n                {\n                    throw new InvalidOperationException(\n                        string.Format(\n                            CultureInfo.CurrentCulture,\n                            DoctorCommandStrings.DcpExitedBeforeKubeconfigDetailsFormat,\n                            _process.ExitCode,\n                            Environment.NewLine,\n                            GetRecentOutput(_output)));\n                }\n\n                await Task.Delay(TimeSpan.FromMilliseconds(100), cancellationToken).ConfigureAwait(false);\n            }\n        }\n\n        private static string GetRecentOutput(OutputCollector output)\n        {\n            var lines = output.GetLines()\n                .TakeLast(40)\n                .Select(line => $\"{line.Stream}: {line.Line}\")\n                .ToArray();","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Utils/EnvironmentChecker/DcpConnectionChecker.cs#L369-L405","documentation":"After starting the DCP server, the checker waits for DCP to write its kubeconfig file. If the process exits before that file appears, WaitForKubeconfigFileAsync throws InvalidOperationException including the process exit code and recent stdout/stderr output, so the actual startup failure (bad flags, port conflicts, crash) is visible.","triggerScenarios":"DcpConnectionChecker session's WaitForKubeconfigFileAsync polling loop observes _process.HasExited == true while the kubeconfig path does not exist - DCP crashed at startup, exited with an argument/configuration error, or was killed before writing kubeconfig.","commonSituations":"DCP failing due to an invalid TLS/developer certificate being passed, port already in use, corrupted DCP installation, incompatible Kubernetes-style flags, or the process being terminated by security software shortly after launch.","solutions":["Read the recent DCP output included in the exception message - it names the real startup error; fix that underlying cause (port conflict, bad flag, cert error).","Check the exit code: non-zero exit usually means configuration error; look for 'address already in use' or certificate messages in the output.","Restart the machine or kill stale dcp processes holding ports, then rerun `aspire doctor`.","Reinstall/update DCP via the Aspire CLI if binaries appear corrupt or version-mismatched."],"exampleFix":"// run doctor and surface the detail\ntry\n{\n    await checker.CheckAsync(options);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Developer Control Plane (DCP) exited\"))\n{\n    Console.Error.WriteLine(ex.Message); // includes exit code + recent output\n}","handlingStrategy":"try-catch","validationCode":"if (File.Exists(kubeconfigPath)) { /* pre-existing kubeconfig from a prior run may mask failures - clear sessions before starting */ Directory.Delete(sessionDirectory, recursive: true); }","typeGuard":null,"tryCatchPattern":"try { var session = await checker.CheckAsync(options); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"exited before writing kubeconfig\")) { Console.Error.WriteLine(ex.Message); /* message already includes exit code + recent DCP output */ }","preventionTips":["Always read the recent-output section of the message; it names the true startup failure.","Kill stale dcp processes and free ports before running doctor.","Keep DCP binaries and the Aspire CLI versions in sync (aspire update)."],"tags":["dcp","kubeconfig","process-exited","doctor","cli"],"backgroundTag":"process-exited-unexpectedly","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"}