microsoft/aspire · error · Win32Exception

Failed to create process

Error message

Failed to create process: {fileName}

What it means

This is thrown when the native CreateProcess call fails while the Aspire CLI spawns a child process on Windows using extended startup attributes (attribute list, environment block, job assignment). The Win32Exception carries the OS error code and the message names the executable that could not be started. It is the final gate after all attribute-list setup succeeded.

Solutions

  1. Check the inner Win32 error: ERROR_FILE_NOT_FOUND/ERROR_PATH_NOT_FOUND means verify the executable path exists (run 'aspire setup --force' to re-extract the CLI bundle).
  2. ERROR_ACCESS_DENIED: check file permissions and antivirus quarantining of the binary.
  3. Verify the working directory passed to the spawn exists and is accessible.
  4. Reinstall or repair the Aspire CLI if the bundle layout is corrupted.

Example fix

// before: spawning with a stale/missing bundle path
// after: force re-extraction, then retry
await bundleService.EnsureExtractedAndAcquireLayoutAsync("cli", "force: true", ct); // run 'aspire setup --force' equivalent
var process = await layoutProcessRunner.StartAsync(managedPath, args, ...);
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(managedPath))
{
    throw new InvalidOperationException($"Executable not found before spawn: {managedPath}. Run 'aspire setup --force'.");
}
if (!Directory.Exists(workingDirectory))
{
    throw new InvalidOperationException($"Working directory does not exist: {workingDirectory}");
}

Try / catch

catch (Win32Exception ex)
{
    var reason = ex.ErrorCode switch
    {
        2 or 3 => "executable or path not found — repair the bundle",
        5 => "access denied — check permissions/antivirus",
        267 => "invalid working directory",
        _ => "unexpected Win32 failure"
    };
    throw new InvalidOperationException($"CreateProcess failed: {reason}", ex);
}

Prevention

When it happens

Trigger: Calling the WindowsProcessInterop process-creation helper (used for dashboard and other child launches with killOnParentExit: true) where CreateProcess returns false — e.g. ERROR_FILE_NOT_FOUND for the executable path, ERROR_ACCESS_DENIED, or invalid working directory.

Common situations: The managed dashboard binary or target executable path is wrong or was deleted mid-run; working directory does not exist; PATH/bundle extraction issues; antivirus quarantining the executable; corrupted bundle layout after a partial 'aspire setup' extraction.

Related errors


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

Appendix: source

Thrown at src/Aspire.Cli/Processes/WindowsProcessInterop.cs:476

                    {
                        if (environment is not null)
                        {
                            envBlockHandle = BuildEnvironmentBlock(environment);
                        }

                        if (!CreateProcessW(
                            null,
                            commandLine,
                            nint.Zero,
                            nint.Zero,
                            bInheritHandles: true,
                            flags,
                            envBlockHandle,
                            workingDirectory,
                            ref si,
                            out var pi))
                        {
                            throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), $"Failed to create process: {fileName}");
                        }

                        return pi;
                    }
                    finally
                    {
                        if (envBlockHandle != nint.Zero)
                        {
                            Marshal.FreeHGlobal(envBlockHandle);
                        }
                    }
                }
                finally
                {
                    if (pinnedJobHandles.IsAllocated)
                    {
                        pinnedJobHandles.Free();
                    }

View on GitHub (pinned to 25830f84bd)