dotnet/runtime · error

Error: Output file name exceeds %d characters

Error message

Error: Output file name exceeds %d characters

What it means

ilasm rejects an output path longer than MAX_FILENAME_LENGTH-1 (2047 chars, defined in assembler.h:33). The `/OUT=<file>` handler (main.cpp:400) measures the wide-string length; at or above the limit it prints this and goes to ErrorExit before copying into the wzOutputFilename buffer.

Source

Thrown at src/coreclr/ilasm/main.cpp:402

                        pAsm->m_wzKeySourceName = pStr;
                    }
                    else if (!_stricmp(szOpt, "INC"))
                    {
                        WCHAR *pStr = EqualOrColon(argv[i]);
                        if(pStr == NULL) goto InvalidOption;
                        for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
                        if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name
                        wzIncludePath = pStr;
                    }
                    else if (!_stricmp(szOpt, "OUT"))
                    {
                        WCHAR *pStr = EqualOrColon(argv[i]);
                        if(pStr == NULL) goto InvalidOption;
                        for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
                        if(u16_strlen(pStr)==0) goto InvalidOption; //if no file name
                        if(u16_strlen(pStr) >= MAX_FILENAME_LENGTH)
                        {
                            fprintf(stderr,"\nError: Output file name exceeds %d characters\n",MAX_FILENAME_LENGTH-1);
                            goto ErrorExit;
                        }
                        wcscpy_s(wzOutputFilename,MAX_FILENAME_LENGTH,pStr);
                    }
                    else if (!_stricmp(szOpt, "MDV"))
                    {
                        WCHAR *pStr = EqualOrColon(argv[i]);
                        if(pStr == NULL) goto InvalidOption;
                        for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
                        if(u16_strlen(pStr)==0) goto InvalidOption; //if no version string
                        pAsm->m_wzMetadataVersion = pStr;
                    }
                    else if (!_stricmp(szOpt, "MSV"))
                    {
                        WCHAR *pStr = EqualOrColon(argv[i]);
                        if(pStr == NULL) goto InvalidOption;
                        for(pStr++; *pStr == W(' '); pStr++); //skip the blanks
                        if(u16_strlen(pStr)==0) goto InvalidOption; //if no version

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Shorten the output path: use a shorter directory or filename.
  2. Set the output to a relative name in the current directory.
  3. Move the build to a shallower workspace root.

Example fix

// before
ilasm /OUT=/very/long/.../repeated/.../MyComponent.dll foo.il
// after
ilasm /OUT=MyComponent.dll foo.il
Defensive patterns

Strategy: validation

Validate before calling

// Validate the /OUT path length before spawning ilasm.
const MAX = 2048 - 1; // MAX_FILENAME_LENGTH-1
if (outPath.length >= MAX) throw new Error('Output path too long for ilasm: ' + outPath.length);

Prevention

When it happens

Trigger: Passing `/OUT=` with a path >= 2048 characters; an environment where the output path is composed from a very long build directory tree.

Common situations: Deeply nested CI workspace paths combined with long assembly names; a typo injecting thousands of characters (e.g. a repeated segment).

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/f9c87a9a19f4178a. Report an issue: GitHub.