{"record":{"id":"9685334e150e985b","repo":"microsoft/aspire","slug":"failed-to-set-nul-handle-inheritance","errorCode":null,"errorMessage":"Failed to set NUL handle inheritance","messagePattern":"Failed to set NUL handle inheritance","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Processes/IsolatedProcess.Windows.cs","lineNumber":211,"sourceCode":"    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,\n            startInfo.GetEnvironmentForSpawn(),\n            createNewConsole: startInfo.IsolateConsole,\n            jobHandle: startInfo.KillOnParentExit ? WindowsConsoleProcessJob.Shared.Handle : null);\n\n        SafeProcessHandle? processHandle = new(pi.hProcess, ownsHandle: true);","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Processes/IsolatedProcess.Windows.cs#L193-L229","documentation":"After opening NUL for a detached child's suppressed stdout/stderr, the handle must be marked inheritable so CreateProcessW can pass it to the child via PROC_THREAD_ATTRIBUTE_HANDLE_LIST. If SetHandleInformation fails, this Win32Exception wrapping the raw Win32 error is thrown. The child has not been spawned yet, so cleanup is trivial.","triggerScenarios":"StartWindowsSuppressed calls WindowsProcessInterop.SetHandleInformation(nulHandle, HandleFlagInherit, HandleFlagInherit) which returns false; GetLastWin32Error typically yields ERROR_INVALID_HANDLE or ERROR_ACCESS_DENIED.","commonSituations":"Failed/invalid NUL handle from the preceding open step, security software tampering with handle flags, restricted-token environments where handle flag modification is denied.","solutions":["Resolve the upstream 'Failed to open NUL device' failure first — ERROR_INVALID_HANDLE here usually means the open returned a bad handle.","Run the CLI under an unrestricted token; check antivirus/EDR handle-flag interception.","Confirm normal handle inheritance works in the environment with a simple CreateProcess test or `start /b` style commands.","Update the Aspire CLI; escalate with the NativeErrorCode if reproducible on a healthy machine."],"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 set NUL handle inheritance\")\n{\n    // Check ex.NativeErrorCode; usually downstream of a failed NUL open or a policy block\n}","preventionTips":["Fix 'Failed to open NUL device' failures first; this error indicates handle-flag manipulation was denied.","Run outside restricted tokens/sandboxes that block SetHandleInformation.","Review security software that intercepts Win32 handle APIs.","Keep the Aspire CLI updated."],"tags":["windows","process","win32","handle-inheritance","detached"],"backgroundTag":"permission-denied","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"}