{"record":{"id":"487e9b30ee0e4990","repo":"dotnet/runtime","slug":"file-alignment-must-be-power-of-2-from-0x200-to-0","errorCode":null,"errorMessage":"\nFile Alignment must be power of 2 from 0x200 to 0x10000\n","messagePattern":"\nFile Alignment must be power of 2 from 0x200 to 0x10000\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/coreclr/ilasm/main.cpp","lineNumber":472,"sourceCode":"                                    pAsm->m_wSSVersionMajor = (WORD)major;\n                                if((minor >= 0)&&(minor < 0xFFFF))\n                                    pAsm->m_wSSVersionMinor = (WORD)minor;\n                            } else\n                                goto InvalidOption;\n                        }\n                    }\n                    else if (!_stricmp(szOpt, \"ALI\"))\n                    {\n                        WCHAR *pStr = EqualOrColon(argv[i]);\n                        if(pStr == NULL) goto InvalidOption;\n                        pStr++;\n                        const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? \"%x\" : \"%d\";\n                        NarrowForNumberParsing str{pStr};\n                        if(sscanf_s(str,pFmt,&g_dwFileAlignment)!=1) goto InvalidOption;\n                        if((g_dwFileAlignment & (g_dwFileAlignment-1))\n                           || (g_dwFileAlignment < 0x200) || (g_dwFileAlignment > 0x10000))\n                        {\n                            fprintf(stderr,\"\\nFile Alignment must be power of 2 from 0x200 to 0x10000\\n\");\n                            if(!pAsm->OnErrGo) goto InvalidOption;\n                        }\n                    }\n                    else if (!_stricmp(szOpt, \"FLA\"))\n                    {\n                        WCHAR *pStr = EqualOrColon(argv[i]);\n                        if(pStr == NULL) goto InvalidOption;\n                        pStr++;\n                        const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? \"%x\" : \"%d\";\n                        NarrowForNumberParsing str{pStr};\n                        if(sscanf_s(str,pFmt,&g_dwComImageFlags)!=1) goto InvalidOption;\n                    }\n                    else if (!_stricmp(szOpt, \"BAS\"))\n                    {\n                        WCHAR *pStr = EqualOrColon(argv[i]);\n                        if(pStr == NULL) goto InvalidOption;\n                        pStr++;\n                        const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? \"%llx\" : \"%lld\";","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/coreclr/ilasm/main.cpp#L454-L490","documentation":"The `/ALI=<n>` (file alignment) switch validates the value in main.cpp:469: it must be a power of two and within [0x200, 0x10000]. The check `(align & (align-1))` detects non-powers-of-two; values outside the PE range are also rejected. When invalid, ilasm prints this and, unless OnErrGo is set, jumps to InvalidOption.","triggerScenarios":"Passing `/ALI=` with a non power-of-two value or a value outside 512..65536 (e.g. `/ALI=0x300`, `/ALI=0x80`, `/ALI=0x20000`).","commonSituations":"Copying a value from another tool's docs; using a decimal where a power-of-two hex was intended; toolchain expecting a specific alignment.","solutions":["Use a power-of-two alignment in range, e.g. `/ALI=0x200` (512), `/ALI=0x1000` (4096), or `/ALI=0x10000` (65536).","Omit `/ALI` entirely to accept the default alignment."],"exampleFix":"// before\nilasm /ALI=0x300 foo.il\n// after\nilasm /ALI=0x200 foo.il","handlingStrategy":"validation","validationCode":"// Validate /ALI value before passing to ilasm.\nfunction validAlignment(v) {\n  return v >= 0x200 && v <= 0x10000 && (v & (v - 1)) === 0;\n}\nif (!validAlignment(align)) throw new Error('Bad file alignment: 0x' + align.toString(16));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to omitting /ALI unless you need a specific alignment.","Prefer hex power-of-two literals (0x200, 0x1000, 0x10000).","Document the [0x200,0x10000] power-of-two rule next to any /ALI usage."],"tags":["ilasm","cli","pe","alignment","validation"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}