{"record":{"id":"b05a2f0cc9ce19a3","repo":"mono/mono","slug":"error-mapping-file-s","errorCode":null,"errorMessage":"Error mapping file: %s\n","messagePattern":"Error mapping file: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"mono/mini/main.c","lineNumber":279,"sourceCode":"\tfor (i = 0; i < items; i++){\n\t\tchar *kind;\n\t\tint strsize = STREAM_INT (p);\n\t\tuint64_t offset;\n\t\tuint32_t item_size;\n\t\tkind = p+4;\n\t\tp += 4 + strsize;\n\t\toffset = STREAM_LONG(p);\n\t\tp += 8;\n\t\titem_size = STREAM_INT (p);\n\t\tp += 4;\n\t\t\n\t\tif (mapaddress == NULL) {\n\t\t\tchar *error_message = NULL;\n\t\t\tmapaddress = (guchar*)mono_file_map_error (directory_location - offset, MONO_MMAP_READ | MONO_MMAP_PRIVATE,\n\t\t\t\tfd, offset, &maphandle, program, &error_message);\n\t\t\tif (mapaddress == NULL) {\n\t\t\t\tif (error_message)\n\t\t\t\t\tfprintf (stderr, \"Error mapping file: %s\\n\", error_message);\n\t\t\t\telse\n\t\t\t\t\tperror (\"Error mapping file\");\n\t\t\t\texit (1);\n\t\t\t}\n\t\t\tbaseline = offset;\n\t\t}\n\t\tif (strncmp (kind, \"assembly:\", strlen (\"assembly:\")) == 0){\n\t\t\tchar *aname = kind + strlen (\"assembly:\");\n\t\t\tMonoBundledAssembly mba = { aname, mapaddress + offset - baseline, item_size }, *ptr;\n\t\t\tptr = g_new (MonoBundledAssembly, 1);\n\t\t\tmemcpy (ptr, &mba, sizeof (MonoBundledAssembly));\n\t\t\tg_array_append_val  (assemblies, ptr);\n\t\t\tif (entry_point == NULL)\n\t\t\t\tentry_point = aname;\n\t\t} else if (strncmp (kind, \"config:\", strlen (\"config:\")) == 0){\n\t\t\tchar *config = kind + strlen (\"config:\");\n\t\t\tchar *aname = g_strdup (config);\n\t\t\taname [strlen(aname)-strlen(\".config\")] = 0;","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/mono/mono/blob/0f53e9e151d92944cacab3e24ac359410c606df6/mono/mini/main.c#L261-L297","documentation":"Fatal error (exit 1) in Mono's bundled-application (mkbundle) loader when mono_file_map_error fails to memory-map a region of the embedded bundle. If an error message is returned it is printed via `%s`; otherwise perror prints the OS errno. The bundle cannot be unpacked, so startup aborts.","triggerScenarios":"mkbundle-embedded application where mmap of an assembly/config region fails (mono_file_map_error returns NULL). error_message non-NULL triggers this fprintf.","commonSituations":"Corrupted or truncated bundled binary, mmap limits exceeded, file descriptor exhaustion, or a bundle built for a different platform/architecture. Running on a filesystem that does not support mmap.","solutions":["Rebuild the bundle with mkbundle to ensure it is not corrupted or truncated.","Check system limits (ulimit -v, /proc/sys/vm/max_map_count) and free file descriptors.","Ensure the bundle was built for the correct target architecture and run on a compatible system."],"exampleFix":"// before\n./mybundle   # corrupted/truncated -> Error mapping file\n\n// after\nmkbundle -o mybundle MyApp.exe --static   # rebuild\n./mybundle","handlingStrategy":"validation","validationCode":"// Verify the bundle file integrity/size before executing.\nconst fs = require('fs');\nfunction bundleLooksOk(p) {\n  try {\n    const st = fs.statSync(p);\n    return st.isFile() && st.size > 0 && fs.accessSync(p, fs.constants.R_OK) === undefined;\n  } catch { return false; }\n}\nif (!bundleLooksOk(bundlePath)) console.error('Bundle missing/empty/unreadable; rebuild with mkbundle.');","typeGuard":null,"tryCatchPattern":"// mmap failure -> exit(1); catch across child process.\ntry {\n  cp.execFileSync('./mybundle', { stdio: 'pipe' });\n} catch (e) {\n  if (/Error mapping file/.test(String(e.stderr))) {\n    console.error('Bundle mmap failed; check corruption, limits, fs support.');\n  }\n}","preventionTips":["Rebuild bundles with mkbundle whenever the Mono runtime version changes.","Check `ulimit -v` and `/proc/sys/vm/max_map_count` before running large bundles.","Run bundles on filesystems that support mmap."],"tags":["mono","mkbundle","bundled","mmap","filesystem"],"backgroundTag":null,"analyzedSha":"0f53e9e151d92944cacab3e24ac359410c606df6","analyzedAt":"2026-08-13T18:54:37.190Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}