{"record":{"id":"b63ec663784ce638","repo":"microsoft/aspire","slug":"the-aspire-extension-token-must-be-set-if-aspire-extension","errorCode":null,"errorMessage":"The Aspire extension token must be set if ASPIRE_EXTENSION_ENDPOINT is set. Please ensure that ASPIRE_EXTENSION_TOKEN is set","messagePattern":"The Aspire extension token must be set if ASPIRE_EXTENSION_ENDPOINT is set\\. Please ensure that ASPIRE_EXTENSION_TOKEN is set","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Aspire.Cli/Backchannel/ExtensionBackchannel.cs","lineNumber":85,"sourceCode":"    private int _connected;\n\n    public ExtensionBackchannel(ILogger<ExtensionBackchannel> logger, IExtensionRpcTarget target, IConfiguration configuration)\n        : this(logger, target, configuration, connectCoreAsyncOverride: null)\n    {\n    }\n\n    internal ExtensionBackchannel(\n        ILogger<ExtensionBackchannel> logger,\n        IExtensionRpcTarget target,\n        IConfiguration configuration,\n        Func<CancellationToken, Task>? connectCoreAsyncOverride)\n    {\n        _logger = logger;\n        _target = target;\n        _configuration = configuration;\n        _connectCoreAsyncOverride = connectCoreAsyncOverride;\n        _token = configuration[KnownConfigNames.ExtensionToken]\n                      ?? throw new InvalidOperationException(ErrorStrings.ExtensionTokenMustBeSet);\n\n        AppDomain.CurrentDomain.ProcessExit += (_, _) =>\n        {\n            if (Volatile.Read(ref _connected) == 0)\n            {\n                return;\n            }\n\n            try\n            {\n                StopDebuggingAsync().GetAwaiter().GetResult();\n            }\n            catch\n            {\n                // This may fail if the extension is deactivated before the aspire cli process is stopped\n                // or if an active debug session is not occurring. Both of these are fine, we just want to\n                // ensure we try to stop the debug session if one is active.\n            }","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Backchannel/ExtensionBackchannel.cs#L67-L103","documentation":"The ExtensionBackchannel constructor reads the extension auth token from configuration (KnownConfigNames.ExtensionToken). If ASPIRE_EXTENSION_ENDPOINT is configured but ASPIRE_EXTENSION_TOKEN is missing, the token is null and the constructor throws this InvalidOperationException, because connecting to the extension endpoint requires the paired token for authentication.","triggerScenarios":"Constructing ExtensionBackchannel (e.g., during CLI startup wiring) when configuration contains ASPIRE_EXTENSION_ENDPOINT but no ASPIRE_EXTENSION_TOKEN value.","commonSituations":"Users partially configure the VS Code extension integration: they set the endpoint env var (often exported by the extension) but the token variable is lost — not inherited into a spawned terminal, cleared by a shell profile, or simply never set.","solutions":["Set the ASPIRE_EXTENSION_TOKEN environment variable to the token provided by the Aspire VS Code extension, then restart the CLI.","Verify both ASPIRE_EXTENSION_ENDPOINT and ASPIRE_EXTENSION_TOKEN are exported in the environment where the CLI runs (echo them to confirm).","If you do not intend to use the extension, unset ASPIRE_EXTENSION_ENDPOINT so the extension backchannel is not initialized."],"exampleFix":"// before\nexport ASPIRE_EXTENSION_ENDPOINT=https://127.0.0.1:54321\n\n// after\nexport ASPIRE_EXTENSION_ENDPOINT=https://127.0.0.1:54321\nexport ASPIRE_EXTENSION_TOKEN=<token-from-extension>","handlingStrategy":"validation","validationCode":"if (Environment.GetEnvironmentVariable(\"ASPIRE_EXTENSION_ENDPOINT\") is not null &&\n    Environment.GetEnvironmentVariable(\"ASPIRE_EXTENSION_TOKEN\") is null)\n{\n    throw new InvalidOperationException(\"ASPIRE_EXTENSION_TOKEN must be set when ASPIRE_EXTENSION_ENDPOINT is set.\");\n}","typeGuard":null,"tryCatchPattern":"try { var bc = new ExtensionBackchannel(logger, target, configuration, null); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"token must be set\"))\n{ /* surface missing ASPIRE_EXTENSION_TOKEN guidance */ }","preventionTips":["Always set ASPIRE_EXTENSION_TOKEN and ASPIRE_EXTENSION_ENDPOINT together, as exported by the extension.","Ensure spawned terminals/agents inherit both env vars (avoid clearing them in shell profiles).","Unset ASPIRE_EXTENSION_ENDPOINT if extension integration is not intended."],"tags":["configuration","environment","extension","authentication"],"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-21T04:17:39.646Z"}