{"record":{"id":"b1506cc49f9e4daa","repo":"microsoft/aspire","slug":"failed-to-open-nul-device-for-stdin","errorCode":null,"errorMessage":"Failed to open NUL device for stdin","messagePattern":"Failed to open NUL device for stdin","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Processes/IsolatedProcess.Windows.cs","lineNumber":51,"sourceCode":"    private static StartedProcess StartWindows(IsolatedProcessStartInfo startInfo)\n    {\n        if (startInfo.Detached)\n        {\n            return StartWindowsSuppressed(startInfo);\n        }\n\n        var nulStdinHandle = WindowsProcessInterop.CreateFileW(\n            \"NUL\",\n            WindowsProcessInterop.GenericRead,\n            WindowsProcessInterop.FileShareRead,\n            nint.Zero,\n            WindowsProcessInterop.OpenExisting,\n            0,\n            nint.Zero);\n\n        if (nulStdinHandle.IsInvalid)\n        {\n            throw new Win32Exception(Marshal.GetLastWin32Error(), \"Failed to open NUL device for stdin\");\n        }\n\n        AnonymousPipeServerStream? stdoutPipe = null;\n        AnonymousPipeServerStream? stderrPipe = null;\n\n        try\n        {\n            if (!WindowsProcessInterop.SetHandleInformation(nulStdinHandle, WindowsProcessInterop.HandleFlagInherit, WindowsProcessInterop.HandleFlagInherit))\n            {\n                throw new Win32Exception(Marshal.GetLastWin32Error(), \"Failed to set NUL stdin handle inheritance\");\n            }\n\n            // PipeDirection.In = server reads, client writes. Inheritable is REQUIRED:\n            // PROC_THREAD_ATTRIBUTE_HANDLE_LIST restricts WHICH handles get inherited but does\n            // NOT promote non-inheritable handles to inheritable ones. Without this flag the\n            // child would see ERROR_INVALID_HANDLE on its stdout/stderr writes.\n            stdoutPipe = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);\n            stderrPipe = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Processes/IsolatedProcess.Windows.cs#L33-L69","documentation":"When spawning a non-detached child on Windows, IsolatedProcess opens the NUL device (CreateFileW \"NUL\") to use as the child's stdin handle, since no input is provided. If CreateFileW returns an invalid handle, a Win32Exception carrying the raw Win32 error is thrown. Without a valid stdin handle the child's stdio wiring (STARTF_USESTDHANDLES) would be incomplete.","triggerScenarios":"StartWindows calls CreateFileW(\"NUL\", GenericRead, FileShareRead, ..., OpenExisting, 0, null) and the returned SafeFileHandle.IsInvalid is true — the Win32 error code comes from Marshal.GetLastWin32Error() immediately after.","commonSituations":"Broken or removed NUL device driver on the machine, heavily restricted security software / device-object ACLs blocking \\Device\\Null, running in an unusual container or Job sandbox where the NUL device is unavailable, or a corrupted Windows installation.","solutions":["Check the inner Win32Exception NativeErrorCode: ERROR_FILE_NOT_FOUND/ERROR_PATH_NOT_FOUND usually means the NUL device driver is broken — verify with `echo test > NUL` in cmd.","Restart the machine or repair Windows to restore the NUL device object if `> NUL` fails.","Check antivirus / endpoint-protection or AppContainer policies that may block opening device objects, and add an exclusion for the CLI process.","Try reproducing in a plain console (outside containers/CI sandboxes) to isolate sandbox interference.","Update the Aspire CLI; if the environment is confirmed healthy but the error persists, file an issue."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var process = isolatedProcess.Start(startInfo);\n}\ncatch (Win32Exception ex) when (ex.Message == \"Failed to open NUL device for stdin\")\n{\n    // Surface ex.NativeErrorCode; treat as machine-level NUL device or policy problem\n}","preventionTips":["Verify `echo test > NUL` works on developer machines and CI images before running Aspire workloads.","Keep endpoint-protection exclusions for CLI/DCP processes on locked-down machines.","Avoid running the CLI in minimal containers that strip the NUL device.","Repair Windows promptly if device objects break after driver/filter updates."],"tags":["windows","process","win32","device-io"],"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"}