dotnet/runtime · error
File Alignment must be power of 2 from 0x200 to 0x10000
Error message
File Alignment must be power of 2 from 0x200 to 0x10000
What it means
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.
Source
Thrown at src/coreclr/ilasm/main.cpp:472
pAsm->m_wSSVersionMajor = (WORD)major;
if((minor >= 0)&&(minor < 0xFFFF))
pAsm->m_wSSVersionMinor = (WORD)minor;
} else
goto InvalidOption;
}
}
else if (!_stricmp(szOpt, "ALI"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&g_dwFileAlignment)!=1) goto InvalidOption;
if((g_dwFileAlignment & (g_dwFileAlignment-1))
|| (g_dwFileAlignment < 0x200) || (g_dwFileAlignment > 0x10000))
{
fprintf(stderr,"\nFile Alignment must be power of 2 from 0x200 to 0x10000\n");
if(!pAsm->OnErrGo) goto InvalidOption;
}
}
else if (!_stricmp(szOpt, "FLA"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%x" : "%d";
NarrowForNumberParsing str{pStr};
if(sscanf_s(str,pFmt,&g_dwComImageFlags)!=1) goto InvalidOption;
}
else if (!_stricmp(szOpt, "BAS"))
{
WCHAR *pStr = EqualOrColon(argv[i]);
if(pStr == NULL) goto InvalidOption;
pStr++;
const CHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? "%llx" : "%lld";View on GitHub (pinned to 290d5ab72c)
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.
Example fix
// before ilasm /ALI=0x300 foo.il // after ilasm /ALI=0x200 foo.il
Defensive patterns
Strategy: validation
Validate before calling
// Validate /ALI value before passing to ilasm.
function validAlignment(v) {
return v >= 0x200 && v <= 0x10000 && (v & (v - 1)) === 0;
}
if (!validAlignment(align)) throw new Error('Bad file alignment: 0x' + align.toString(16)); Prevention
- 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.
When it happens
Trigger: Passing `/ALI=` with a non power-of-two value or a value outside 512..65536 (e.g. `/ALI=0x300`, `/ALI=0x80`, `/ALI=0x20000`).
Common situations: Copying a value from another tool's docs; using a decimal where a power-of-two hex was intended; toolchain expecting a specific alignment.
Related errors
- Base address must be 0x10000-aligned
- Invalid Image Base specified for 32-bit target
- Error: Output file name exceeds %d characters
- Error : Invalid Option: %s
- event.eventName is a required parameter, in event: ${JSON.st
AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06).
Data as JSON: /api/errors/487e9b30ee0e4990.
Report an issue: GitHub.