{"record":{"id":"38bf50af192fc5c6","repo":"microsoft/aspire","slug":"unexpected-task-hub-name-type-taskhubnameannotation-hubname","errorCode":null,"errorMessage":"Unexpected Task Hub name type: {taskHubNameAnnotation.HubName.GetType().Name}","messagePattern":"Unexpected Task Hub name type: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Functions/DurableTask/DurableTaskHubResource.cs","lineNumber":52,"sourceCode":"    public ReferenceExpression TaskHubName => GetTaskHubName();\n\n    /// <inheritdoc />\n    void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName)\n    {\n        // Injected to support Azure Functions listener initialization via the DTS storage provider.\n        target[\"DURABLE_TASK_SCHEDULER_CONNECTION_STRING\"] = Parent.ConnectionStringExpression;\n        target[\"TASKHUB_NAME\"] = TaskHubName;\n    }\n\n    private ReferenceExpression GetTaskHubName()\n    {\n        if (this.TryGetLastAnnotation<DurableTaskHubNameAnnotation>(out var taskHubNameAnnotation))\n        {\n            return taskHubNameAnnotation.HubName switch\n            {\n                ParameterResource parameter => ReferenceExpression.Create($\"{parameter}\"),\n                string hubName => ReferenceExpression.Create($\"{hubName}\"),\n                _ => throw new InvalidOperationException($\"Unexpected Task Hub name type: {taskHubNameAnnotation.HubName.GetType().Name}\")\n            };\n        }\n\n        return ReferenceExpression.Create($\"{Name}\");\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":59,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Functions/DurableTask/DurableTaskHubResource.cs#L34-L59","documentation":"DurableTaskHubResource.TaskHubName converts the hub name stored in DurableTaskHubNameAnnotation into a ReferenceExpression. The annotation's HubName is expected to be either a string or a ParameterResource; any other stored type means the union type constraint was violated somewhere, so GetTaskHubName throws this InvalidOperationException as an internal invariant guard.","triggerScenarios":"Attaching a DurableTaskHubNameAnnotation whose HubName is neither string nor ParameterResource (custom code or a future API misuse), then reading TaskHubName.","commonSituations":"Custom Durable Task extension code constructing the annotation with an unvalidated value; calling internal APIs with a ReferenceExpression or other type instead of the supported union members.","solutions":["Pass either a string literal or a ParameterResource (e.g., builder.AddParameter(...).Resource) as the task hub name.","Inspect the annotation construction site and fix the type of HubName.","If using a builder API, rely on the [AspireUnion]-attributed overloads (WithTaskHubName) which validate the type at call time."],"exampleFix":"// before\nhubResource.Annotations.Add(new DurableTaskHubNameAnnotation(someExpression));\n\n// after\nvar hubParam = builder.AddParameter(\"hub-name\");\nhubResource.WithTaskHubName(hubParam); // stores a ParameterResource","handlingStrategy":"type-guard","validationCode":"if (hubName is not string and not ParameterResource) throw new InvalidOperationException($\"Task hub name must be string or ParameterResource, got {hubName?.GetType().Name}\");","typeGuard":"static bool IsValidHubName(object? v) => v is string or ParameterResource;","tryCatchPattern":"try { var expr = hubResource.TaskHubName; } catch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Unexpected Task Hub name type\")) { /* fix annotation producer */ }","preventionTips":["Only create DurableTaskHubNameAnnotation with string or ParameterResource values.","Use the public WithTaskHubName overloads instead of raw annotations.","Validate types at annotation construction."],"tags":["aspire","durable-task","type-mismatch","internal"],"backgroundTag":"type-mismatch","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"}