{"record":{"id":"cb66c349715671ef","repo":"microsoft/aspire","slug":"failed-to-open-nul-device","errorCode":null,"errorMessage":"Failed to open NUL device","messagePattern":"Failed to open NUL device","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Processes/IsolatedProcess.Windows.cs","lineNumber":206,"sourceCode":"            throw;\n        }\n    }\n\n    [SupportedOSPlatform(\"windows\")]\n    private static StartedProcess StartWindowsSuppressed(IsolatedProcessStartInfo startInfo)\n    {\n        using var nulHandle = WindowsProcessInterop.CreateFileW(\n            \"NUL\",\n            WindowsProcessInterop.GenericWrite,\n            WindowsProcessInterop.FileShareWrite,\n            nint.Zero,\n            WindowsProcessInterop.OpenExisting,\n            0,\n            nint.Zero);\n\n        if (nulHandle.IsInvalid)\n        {\n            throw new Win32Exception(Marshal.GetLastWin32Error(), \"Failed to open NUL device\");\n        }\n\n        if (!WindowsProcessInterop.SetHandleInformation(nulHandle, WindowsProcessInterop.HandleFlagInherit, WindowsProcessInterop.HandleFlagInherit))\n        {\n            throw new Win32Exception(Marshal.GetLastWin32Error(), \"Failed to set NUL handle inheritance\");\n        }\n\n        var nulRawHandle = nulHandle.DangerousGetHandle();\n        var stdio = new WindowsProcessInterop.StdioHandles(\n            Stdin: nint.Zero,\n            Stdout: nulRawHandle,\n            Stderr: nulRawHandle);\n\n        var pi = WindowsProcessInterop.SpawnProcess(\n            startInfo.FileName,\n            startInfo.ArgumentList,\n            startInfo.WorkingDirectory,\n            stdio,","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Processes/IsolatedProcess.Windows.cs#L188-L224","documentation":"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.","triggerScenarios":"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.","commonSituations":"Broken NUL device/driver, security or sandbox software blocking device-object opens, running inside a restricted container without the NUL device, corrupted Windows install.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var process = isolatedProcess.Start(detachedStartInfo);\n}\ncatch (Win32Exception ex) when (ex.Message == \"Failed to open NUL device\")\n{\n    // Inspect ex.NativeErrorCode; NUL device or sandbox issue — no child was created\n}","preventionTips":["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."],"tags":["windows","process","win32","device-io","detached"],"backgroundTag":"file-open-failed","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"}