{"record":{"id":"7fe45c6241148785","repo":"microsoft/aspire","slug":"cannot-create-task-reporter-is-not-set","errorCode":null,"errorMessage":"Cannot create task: Reporter is not set.","messagePattern":"Cannot create task: Reporter is not set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Pipelines/ReportingStep.cs","lineNumber":110,"sourceCode":"        }\n\n        var maxState = CompletionState.InProgress;\n        foreach (var task in _tasks.Values)\n        {\n            if ((int)task.CompletionState > (int)maxState)\n            {\n                maxState = task.CompletionState;\n            }\n        }\n        return maxState;\n    }\n\n    /// <inheritdoc />\n    public async Task<IReportingTask> CreateTaskAsync(string statusText, CancellationToken cancellationToken = default)\n    {\n        if (Reporter is null)\n        {\n            throw new InvalidOperationException(\"Cannot create task: Reporter is not set.\");\n        }\n\n        return await Reporter.CreateTaskAsync(this, statusText, enableMarkdown: false, cancellationToken: cancellationToken).ConfigureAwait(false);\n    }\n\n    /// <inheritdoc />\n    public async Task<IReportingTask> CreateTaskAsync(MarkdownString statusText, CancellationToken cancellationToken = default)\n    {\n        ArgumentNullException.ThrowIfNull(statusText);\n\n        if (Reporter is null)\n        {\n            throw new InvalidOperationException(\"Cannot create task: Reporter is not set.\");\n        }\n\n        return await Reporter.CreateTaskAsync(this, statusText.Value, enableMarkdown: true, cancellationToken: cancellationToken).ConfigureAwait(false);\n    }\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Pipelines/ReportingStep.cs#L92-L128","documentation":"ReportingStep.CreateTaskAsync(string, CancellationToken) throws InvalidOperationException when the step's Reporter property has not been set. The step delegates task creation to its IStepReporter; without a reporter there is nowhere to create the task. This is a configuration/lifecycle error — the step must be initialized with a reporter before use.","triggerScenarios":"Calling await step.CreateTaskAsync(\"status\") on a ReportingStep that was obtained or constructed without its Reporter being assigned (e.g. used outside the normal pipeline execution flow, or before the pipeline attaches its reporter).","commonSituations":"Custom pipeline code grabbing a ReportingStep and creating tasks directly, unit tests constructing ReportingStep manually, or code running after the pipeline context has disposed/reset the reporter.","solutions":["Ensure the ReportingStep is created/obtained through the pipeline execution infrastructure so Reporter is attached.","Assign a valid IStepReporter (or equivalent) to the step's Reporter property before calling CreateTaskAsync.","In tests, supply a test/fake reporter instead of using a bare step.","Check for null with the pattern below before calling CreateTaskAsync."],"exampleFix":"// before\nvar task = await step.CreateTaskAsync(\"Building image...\");\n\n// after\nif (step.Reporter is null)\n{\n    throw new InvalidOperationException(\"Attach a reporter to the step before creating tasks.\");\n}\nvar task = await step.CreateTaskAsync(\"Building image...\");","handlingStrategy":"type-guard","validationCode":"if (step.Reporter is null)\n{\n    throw new InvalidOperationException(\"Step has no reporter; create it via the pipeline API.\");\n}","typeGuard":"bool canCreateTask = step.Reporter is not null;","tryCatchPattern":"try\n{\n    var task = await step.CreateTaskAsync(statusText);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Reporter is not set\"))\n{\n    logger.LogError(ex, \"ReportingStep used without a reporter; use the pipeline API to create steps.\");\n}","preventionTips":["Create steps through the pipeline execution API, never manually.","Do not retain ReportingStep references past pipeline context disposal.","Use a fake reporter in unit tests."],"tags":["pipelines","reporting","not-initialized"],"backgroundTag":"missing-dependency","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}