{"record":{"id":"a267cab2f9f69631","repo":"microsoft/aspire","slug":"failed-to-initialize-process-thread-attribute-list","errorCode":null,"errorMessage":"Failed to initialize process thread attribute list","messagePattern":"Failed to initialize process thread attribute list","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Processes/WindowsProcessInterop.cs","lineNumber":392,"sourceCode":"            }\n        }\n        AddIfUnique(stdio.Stdin);\n        AddIfUnique(stdio.Stdout);\n        AddIfUnique(stdio.Stderr);\n\n        // The child always needs the stdio handle whitelist; when a parent-lifetime job is supplied it\n        // ALSO needs PROC_THREAD_ATTRIBUTE_JOB_LIST so the child is assigned to the job atomically at creation (below).\n        var attributeCount = jobHandle is not null ? 2 : 1;\n\n        var attrListSize = nint.Zero;\n        InitializeProcThreadAttributeList(nint.Zero, attributeCount, 0, ref attrListSize);\n\n        var attrList = Marshal.AllocHGlobal(attrListSize);\n        try\n        {\n            if (!InitializeProcThreadAttributeList(attrList, attributeCount, 0, ref attrListSize))\n            {\n                throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), \"Failed to initialize process thread attribute list\");\n            }\n\n            try\n            {\n                var handles = inheritable.ToArray();\n                var pinnedHandles = GCHandle.Alloc(handles, GCHandleType.Pinned);\n                var pinnedJobHandles = default(GCHandle);\n                var jobHandleRefAdded = false;\n\n                try\n                {\n                    if (!UpdateProcThreadAttribute(\n                        attrList,\n                        0,\n                        ProcThreadAttributeHandleList,\n                        pinnedHandles.AddrOfPinnedObject(),\n                        (nint)(nint.Size * handles.Length),\n                        nint.Zero,","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Processes/WindowsProcessInterop.cs#L374-L410","documentation":"When the Aspire CLI spawns a process on Windows with an explicit inheritable-handle list or job assignment, it builds a PROC_THREAD_ATTRIBUTE_LIST via InitializeProcThreadAttributeList. This error is thrown when that native call returns false, wrapped with the last Win32 error. Without the attribute list the extended process-creation attributes (handle inheritance, job list) cannot be used.","triggerScenarios":"Calling WindowsProcessInterop process-creation helpers (e.g. when starting a child process with killOnParentExit: true or explicit handle inheritance) where InitializeProcThreadAttributeList fails with the requested attributeCount.","commonSituations":"Memory exhaustion (AllocHGlobal succeeded but the native init failed); malformed attribute count calculations after marshalling changes; running on very old or stripped Windows versions; interference from security software hooking process-creation APIs.","solutions":["Check the inner Win32Exception error code; ERROR_INSUFFICIENT_BUFFER usually means retry sizing — report as a bug if the CLI pre-computed attrListSize.","Free up memory / address low-memory conditions on the machine.","Verify the Windows version supports PROC_THREAD_ATTRIBUTE_LIST (Windows Vista+; effectively all supported systems).","Update the Aspire CLI — a marshalling/size bug would be a CLI defect to report."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var pi = WindowsProcessInterop.CreateProcessWithAttributes(...);\n}\ncatch (Win32Exception ex)\n{\n    logger.LogError(ex, \"Attribute list init failed (Win32 error {Code}); falling back to plain CreateProcess.\", ex.ErrorCode);\n}","preventionTips":["Avoid running under severe memory pressure.","Report reproducible failures with the inner Win32 code to the CLI maintainers.","Keep Windows updated."],"tags":["windows","win32","process-management","interop","cli"],"backgroundTag":"win32-api-call-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"}