microsoft/aspire · error · InvalidOperationException

Build failed for resource

Error message

Build failed for resource '{resource.Name}' with exit code {process.ExitCode}.

What it means

After the MAUI build process exits, RunBuildAsync checks its exit code. A non-zero exit code means compilation/build failed; the subscriber throws InvalidOperationException with the exit code so the resource fails to start. Stdout/stderr are already drained and logged to help diagnose.

Solutions

  1. Read the captured build stdout/stderr logs near this error to find the actual MSBuild error, then fix that error.
  2. Install/repair required workloads: dotnet workload install maui (plus maui-ios/maui-android/maui-maccatalyst as needed).
  3. Verify the target platform SDKs (Xcode for MacCatalyst/iOS, Android SDK/SDK manager) are installed and version-compatible.
  4. Build the MAUI project directly with dotnet build to reproduce and fix outside Aspire, then restart the AppHost.

Example fix

// before
// missing workload causes exit code 1
dotnet run --project AppHost;
// after
dotnet workload install maui-ios maui-maccatalyst && dotnet run --project AppHost;
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight outside Aspire
var psi = new ProcessStartInfo("dotnet", $"build {mauiProject} -f {targetFramework}"); // non-zero exit here predicts the Aspire error

Try / catch

try { await startMauiResourceAsync(); } catch (InvalidOperationException ex) when (ex.Message.Contains("Build failed")) { // inspect captured build stdout/stderr logs for the MSBuild error }

Prevention

When it happens

Trigger: The dotnet build invoked for the MAUI resource exits non-zero — compile errors, missing workloads (e.g. ios/android), missing TargetFrameworks, invalid signing/bundle settings — surfacing at src/Aspire.Hosting.Maui/Lifecycle/MauiBuildQueueEventSubscriber.cs:252.

Common situations: Missing MAUI workloads or SDKs on the machine; Xcode/Android SDK version mismatches; code compile errors after edits; NuGet restore failures; unsupported target framework for the selected platform.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/2bd3af3a13a59790. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Maui/Lifecycle/MauiBuildQueueEventSubscriber.cs:252

            TryKillProcess(process, logger);
            throw new TimeoutException(
                $"Build for resource '{resource.Name}' timed out after {BuildTimeout:c}.");
        }
        catch (OperationCanceledException)
        {
            TryKillProcess(process, logger);
            throw;
        }
        finally
        {
            // Always drain remaining output — even on cancellation the process was killed
            // and the streams will reach EOF, so the tasks will complete promptly.
            await Task.WhenAll(stdoutTask, stderrTask).ConfigureAwait(false);
        }

        if (process.ExitCode != 0)
        {
            throw new InvalidOperationException(
                $"Build failed for resource '{resource.Name}' with exit code {process.ExitCode}.");
        }

        logger.LogInformation("Build succeeded for resource '{ResourceName}'.", resource.Name);
    }

    private static async Task PipeOutputAsync(System.IO.StreamReader reader, ILogger logger, LogLevel level, CancellationToken cancellationToken)
    {
        try
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                var line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false);
                if (line is null)
                {
                    break;
                }

View on GitHub (pinned to 25830f84bd)