{"record":{"id":"b3edb6984746edcb","repo":"microsoft/aspire","slug":"the-developer-certificate-could-not-be-cached-because-the","errorCode":null,"errorMessage":"The developer certificate could not be cached because the user profile directory could not be determined.","messagePattern":"The developer certificate could not be cached because the user profile directory could not be determined\\.","errorType":"exception","errorClass":"DcpDeveloperCertificateUnavailableException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Utils/EnvironmentChecker/DcpDeveloperCertificateCache.cs","lineNumber":24,"sourceCode":"using Aspire.Cli.Resources;\nusing Aspire.Hosting.Utils;\nusing Microsoft.AspNetCore.Certificates.Generation;\n\nnamespace Aspire.Cli.Utils.EnvironmentChecker;\n\ninternal static class DcpDeveloperCertificateCache\n{\n    public static string EnsureDeveloperCertificateCache(CertificateManager certificateManager, X509Certificate2 certificate)\n    {\n        if (!certificate.IsAspNetCoreDevelopmentCertificate() || string.IsNullOrWhiteSpace(certificate.Thumbprint))\n        {\n            throw new DcpDeveloperCertificateUnavailableException(DoctorCommandStrings.DcpDeveloperCertificateInvalidForCacheDetails);\n        }\n\n        var cacheDirectory = CertificateHelpers.AspireDevCertsHttpsCacheDirectory;\n        if (!Path.IsPathFullyQualified(cacheDirectory))\n        {\n            throw new DcpDeveloperCertificateUnavailableException(DoctorCommandStrings.DcpDeveloperCertificateUserProfileMissingDetails);\n        }\n\n        var lookup = CertificateHelpers.GetAspireCertificateHash(certificate);\n        var certificatePath = Path.Combine(cacheDirectory, $\"{lookup}.crt\");\n        var keyPath = Path.ChangeExtension(certificatePath, \".key\");\n\n        // The public certificate export does not require private key access, so older caches with\n        // a key but no certificate can be filled without re-exporting the cached key.\n        certificateManager.ExportCertificate(certificate, certificatePath, includePrivateKey: !File.Exists(keyPath), password: null, CertificateKeyExportFormat.Pem);\n\n        return certificatePath;\n    }\n}\n","sourceCodeStart":6,"sourceCodeEnd":38,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Utils/EnvironmentChecker/DcpDeveloperCertificateCache.cs#L6-L38","documentation":"The developer-certificate cache writes the exported cert under CertificateHelpers.AspireDevCertsHttpsCacheDirectory, which is derived from the user profile / home directory. If that base path cannot be resolved to a fully-qualified path (e.g. HOME/USERPROFILE unset or empty), EnsureDeveloperCertificateCache throws DcpDeveloperCertificateUnavailableException because there is nowhere valid to cache the certificate.","triggerScenarios":"EnsureDeveloperCertificateCache runs in an environment where the user profile directory is missing - HOME or USERPROFILE environment variables unset (common in stripped-down service accounts, containers, cron jobs, or SSH sessions with sanitized environments) so the cache directory path is not fully qualified.","commonSituations":"Running `aspire doctor` inside a minimal Docker container without HOME set, systemd service or CI runner accounts with no home directory, sudo/su dropping environment variables, or Windows profiles failing to load for temp accounts.","solutions":["Ensure HOME (Linux/macOS) or USERPROFILE (Windows) is set to a writable directory before running the Aspire CLI.","In containers, run as a user with a defined home (e.g. `docker run -e HOME=/root ...`) or add `-e HOME=$(mktemp -d)`.","If using sudo, preserve the environment (`sudo -E`) or set HOME explicitly.","Create the account's home directory if the user account exists without one, then rerun the command."],"exampleFix":"// before (container entrypoint)\naspire doctor\n// after\nexport HOME=${HOME:-/root}\nmkdir -p \"$HOME\"\naspire doctor","handlingStrategy":"validation","validationCode":"var home = OperatingSystem.IsWindows() ? Environment.GetEnvironmentVariable(\"USERPROFILE\") : Environment.GetEnvironmentVariable(\"HOME\");\nif (string.IsNullOrWhiteSpace(home) || !Directory.Exists(home))\n    Console.WriteLine(\"User profile directory missing; set HOME/USERPROFILE before running aspire.\");","typeGuard":null,"tryCatchPattern":"try { DcpDeveloperCertificateCache.EnsureDeveloperCertificateCache(manager, cert); }\ncatch (DcpDeveloperCertificateUnavailableException ex) when (ex.Message.Contains(\"user profile\")) { Console.Error.WriteLine(\"Set HOME/USERPROFILE to a writable directory and retry.\"); }","preventionTips":["Always set HOME (Unix) or USERPROFILE (Windows) in containers, services, and CI jobs.","Use `sudo -E` or explicit env passing so the user profile survives privilege elevation.","Create a home directory for service accounts that lack one."],"tags":["dcp","certificate","cache","environment","home-directory"],"backgroundTag":"missing-env-var","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}