microsoft/aspire · error · Win32Exception
Failed to open NUL device
Error message
Failed to open NUL device
What it means
For detached children on Windows, StartWindowsSuppressed opens the NUL device to serve as both stdout and stderr (all child output is suppressed). If CreateFileW("NUL") returns an invalid handle, this Win32Exception is thrown with the underlying Win32 error code. The child has not been created yet at this point, so nothing leaks.
Solutions
- Check NativeErrorCode and verify the NUL device works: `echo test > NUL` from cmd.
- Repair Windows / reboot if the NUL device driver is broken (often after driver or storage filter issues).
- Review endpoint-protection or container policies that block \Device\Null opens and whitelist the CLI.
- Retry outside the sandboxed environment (CI runner, AppContainer, Job object) to confirm the cause.
- Update the Aspire CLI and report with the exact Win32 error code if the environment is healthy.
Defensive patterns
Strategy: try-catch
Try / catch
try
{
var process = isolatedProcess.Start(detachedStartInfo);
}
catch (Win32Exception ex) when (ex.Message == "Failed to open NUL device")
{
// Inspect ex.NativeErrorCode; NUL device or sandbox issue — no child was created
} Prevention
- Confirm the NUL device is healthy (`echo test > NUL`) in any environment that runs detached Aspire children.
- Whitelist the CLI in endpoint-protection and container device policies.
- Prefer standard CI runner images over stripped custom images.
- Reboot/repair Windows after storage-filter or driver failures that break device objects.
When it happens
Trigger: StartWindows routes a Detached=true start through StartWindowsSuppressed, which calls CreateFileW("NUL", ..., OpenExisting, 0, null); the returned handle IsInvalid and Marshal.GetLastWin32Error() supplies the error code.
Common situations: Broken NUL device/driver, security or sandbox software blocking device-object opens, running inside a restricted container without the NUL device, corrupted Windows install.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- Failed to open NUL device for stdin
- Failed to set NUL handle inheritance
- Failed to create CLI kill-on-parent-exit job object
- Failed to set NUL stdin handle inheritance
- GetExitCodeProcess failed while reading…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/cb66c349715671ef.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Cli/Processes/IsolatedProcess.Windows.cs:206
throw;
}
}
[SupportedOSPlatform("windows")]
private static StartedProcess StartWindowsSuppressed(IsolatedProcessStartInfo startInfo)
{
using var nulHandle = WindowsProcessInterop.CreateFileW(
"NUL",
WindowsProcessInterop.GenericWrite,
WindowsProcessInterop.FileShareWrite,
nint.Zero,
WindowsProcessInterop.OpenExisting,
0,
nint.Zero);
if (nulHandle.IsInvalid)
{
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to open NUL device");
}
if (!WindowsProcessInterop.SetHandleInformation(nulHandle, WindowsProcessInterop.HandleFlagInherit, WindowsProcessInterop.HandleFlagInherit))
{
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to set NUL handle inheritance");
}
var nulRawHandle = nulHandle.DangerousGetHandle();
var stdio = new WindowsProcessInterop.StdioHandles(
Stdin: nint.Zero,
Stdout: nulRawHandle,
Stderr: nulRawHandle);
var pi = WindowsProcessInterop.SpawnProcess(
startInfo.FileName,
startInfo.ArgumentList,
startInfo.WorkingDirectory,
stdio,View on GitHub (pinned to 25830f84bd)