{"record":{"id":"b10b173bd5f5dd27","repo":"microsoft/aspire","slug":"invalid-operation-specified-valid-operations-are-publish-run","errorCode":null,"errorMessage":"Invalid operation specified. Valid operations are 'publish', 'run', or 'inspect'.","messagePattern":"Invalid operation specified\\. Valid operations are 'publish', 'run', or 'inspect'\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"critical","filePath":"src/Aspire.Hosting/DistributedApplicationBuilder.cs","lineNumber":155,"sourceCode":"    private readonly DistributedApplicationExecutionContextOptions _executionContextOptions;\n\n    private DistributedApplicationExecutionContextOptions BuildExecutionContextOptions()\n    {\n        var operationConfiguration = _innerBuilder.Configuration[\"AppHost:Operation\"];\n        if (operationConfiguration is null)\n        {\n            return _innerBuilder.Configuration[\"Publishing:Publisher\"] switch\n            {\n                { } publisher => new DistributedApplicationExecutionContextOptions(DistributedApplicationOperation.Publish, publisher),\n                _ => new DistributedApplicationExecutionContextOptions(DistributedApplicationOperation.Run) { RunConfiguration = BuildRunConfiguration() }\n            };\n        }\n\n        return _innerBuilder.Configuration[\"AppHost:Operation\"]?.ToLowerInvariant() switch\n        {\n            \"run\" => new DistributedApplicationExecutionContextOptions(DistributedApplicationOperation.Run) { RunConfiguration = BuildRunConfiguration() },\n            \"publish\" or \"inspect\" => new DistributedApplicationExecutionContextOptions(DistributedApplicationOperation.Publish, _innerBuilder.Configuration[\"Publishing:Publisher\"] ?? \"manifest\"),\n            _ => throw new DistributedApplicationException(\"Invalid operation specified. Valid operations are 'publish', 'run', or 'inspect'.\")\n        };\n    }\n\n    private RunConfiguration BuildRunConfiguration()\n    {\n        // Only \"true\" and \"false\" (case-insensitively) are accepted. bool.TryParse rejects everything else,\n        // including values some configuration sources emit for booleans such as \"1\" or \"yes\". An unusable\n        // value must never fail an otherwise valid run, so anything unrecognized falls back to the default.\n        return new RunConfiguration\n        {\n            WatchEnabled = bool.TryParse(_innerBuilder.Configuration[\"AppHost:Run:WatchEnabled\"], out var watchEnabled) && watchEnabled\n        };\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"DistributedApplicationBuilder\"/> class with the specified options.\n    /// </summary>\n    /// <param name=\"options\">The options for the distributed application.</param>","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/DistributedApplicationBuilder.cs#L137-L173","documentation":"DistributedApplicationBuilder reads the AppHost operation mode from the configuration key 'AppHost:Operation' and only accepts 'run', 'publish', or 'inspect' (case-insensitive). Any other or unrecognized value means the host cannot determine whether it should run the app or produce a publish manifest/inspection output, so it fails fast with a DistributedApplicationException.","triggerScenarios":"Configuration key AppHost:Operation is set to an unrecognized value (e.g. 'Run ' as written via a custom host, 'debug', 'deploy'), or the key is absent in a context where the builder expects it to be set by dotnet run/publish infrastructure.","commonSituations":"Custom AppHost launch setups or test harnesses that set DistributedApplicationOptions/operation via environment variables or appsettings with a typo; invoking the AppHost executable directly without the tooling that normally sets AppHost:Operation; older tooling versions writing a value like 'generate' that the current SDK no longer accepts.","solutions":["Set AppHost:Operation to exactly 'run', 'publish', or 'inspect' in configuration/environment (e.g. DOTNET_ or appsettings key AppHost__Operation).","Run the AppHost through the standard tooling (aspire run / dotnet run / dotnet publish) instead of executing the binary directly, so the operation is configured automatically.","Fix typos and casing-neutral values; the comparison is ToLowerInvariant, so 'RUN' works but 'RunMode' does not."],"exampleFix":"// before (appsettings.json / env)\n\"AppHost\": { \"Operation\": \"deploy\" }\n// after\n\"AppHost\": { \"Operation\": \"publish\" }","handlingStrategy":"validation","validationCode":"var op = builder.Configuration[\"AppHost:Operation\"]?.ToLowerInvariant();\nif (op is not (\"run\" or \"publish\" or \"inspect\"))\n    throw new InvalidOperationException($\"AppHost:Operation '{op}' is invalid; use run, publish, or inspect.\");","typeGuard":null,"tryCatchPattern":"try { var app = builder.Build(); } catch (DistributedApplicationException ex) when (ex.Message.Contains(\"Invalid operation specified\")) { /* log config key AppHost:Operation and correct it */ }","preventionTips":["Only set AppHost:Operation through the standard aspire tooling.","Whitelist-validate any code that sets the operation key programmatically.","Use constants instead of raw strings for the operation value."],"tags":["configuration","apphost","startup"],"backgroundTag":"invalid-enum-value","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"}