dotnet/runtime · error · RuntimeError

MCH file failed to be generated at: %s

Error message

MCH file failed to be generated at: %s

What it means

Raised in `__merge_mc_files__` (superpmi.py:1367-1368) after running `mcs -merge <base.mch> <temp>/*.mc -recursive -dedup -thin`. If the expected base MCH file is not present on disk after the merge command, the merge step failed. `run_and_log` does not itself raise on non-zero exit, so this post-check is the failure signal.

Source

Thrown at src/coreclr/scripts/superpmi.py:1368

            raise RuntimeError("No .mc files generated.")

    def __merge_mc_files__(self):
        """ Merge the mc files that were generated

        Notes:
            mcs -merge <s_baseMchFile> <s_tempDir>\\*.mc -recursive -dedup -thin

        """

        logging.info("Merging MC files")

        pattern = os.path.join(self.temp_location, "*.mc")

        command = [self.mcs_path, "-merge", self.base_mch_file, pattern, "-recursive", "-dedup", "-thin"]
        run_and_log(command)

        if not os.path.isfile(self.base_mch_file):
            raise RuntimeError("MCH file failed to be generated at: %s" % self.base_mch_file)

        # All the individual MC files are no longer necessary, now that we have
        # merged them into the base.mch. Delete them.
        if not self.coreclr_args.skip_cleanup:
            mc_files = [os.path.join(self.temp_location, item) for item in os.listdir(self.temp_location) if item.endswith(".mc")]
            for item in mc_files:
                os.remove(item)

    def __merge_mch_files__(self):
        """ Merge MCH files in the mch_files list. This is only used with the `--merge_mch_files` argument.

        Notes:
            mcs -concat <s_baseMchFile> [self.coreclr_args.mch_files]

        """

        logging.info("Merging MCH files")

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Inspect the mcs `-merge` command output logged just before this error for the underlying mcs error/return code.
  2. Confirm the `.mc` files in temp_location are non-empty and valid before merging.
  3. Ensure the mcs binary matches the runtime/JIT build and the temp directory has free disk space.
Defensive patterns

Strategy: try-catch

Validate before calling

# Confirm non-empty .mc inputs and mcs exists before merging
if not any(os.path.getsize(m) > 0 for m in glob.glob(temp + '/*.mc')):
    raise SystemExit('No non-empty .mc files to merge.')
if not shutil.which('mcs') and not os.path.isfile(mcs_path):
    raise SystemExit('mcs tool not found; build the runtime first.')

Try / catch

try:
    collection.__merge_mc_files__()
except RuntimeError as e:
    if 'MCH file failed' in str(e):
        logging.error('mcs -merge failed; check the logged mcs output and disk space.')
    raise

Prevention

When it happens

Trigger: The mcs tool crashed or returned an error during the `-merge` operation, leaving no base_mch_file behind. Causes: corrupt/empty input `.mc` files, a broken/missing mcs binary, insufficient disk space, or a permission error writing the MCH.

Common situations: The preceding collection produced zero-length or corrupt `.mc` files (see error 163 territory); mcs version mismatch with the runtime build; disk full on the temp drive during a large merge.

Related errors


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