Unity-Technologies/UnityCsReference · error · InvalidOperationException

Could not determine which of the {candidates.Length} of {too

Error message

Could not determine which of the {candidates.Length} of {toolName} to use.  The expected TFM or expected directory layout may have changed and this logic may need to be updated

What it means

Thrown after candidates for an IL2CPP tool were found, but none matched either the non-published layout (bin/<config>/<tfm>/exe) or the published layout (bin/<config>/<tfm>/publish/<platformDir>/exe). This means the on-disk directory structure changed and the heuristic cannot pick a binary.

Source

Thrown at Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:619

                        return candidate.ToString();
                    }

                    // Examples :
                    // 1)   il2cpp/bin/Release/<tfm>/<platform dir>/publish/il2cpp.exe
                    // 2)   il2cpp/bin/Debug/<tfm>/<platform dir>/publish/il2cpp.exe
                    if (candidate.Parent.FileName == "publish" && candidate.Parent.Parent.FileName == expectedPublishDirectoryName)
                    {
                        // found a published build
                        return candidate.ToString();
                    }

                    // There is a 3rd path structure that we will ignore
                    // Examples :
                    // 1)   il2cpp/bin/Release/<tfm>/<platform dir>/il2cpp.exe
                    // 2)   il2cpp/bin/Debug/<tfm>/<platform dir>/il2cpp.exe
                }

                throw new InvalidOperationException($"Could not determine which of the {candidates.Length} of {toolName} to use.  The expected TFM or expected directory layout may have changed and this logic may need to be updated");
            }

            var deployDirectory = $"{il2CppFolder}/build/deploy";
            return $"{deployDirectory}/{expectedToolExecutableName}";
        }

        internal static string GetLibrarySearchPaths(string name, string tfm, string customRoot = null)
        {
            var il2CppFolder = GetIl2CppFolder(out var isDevelopmentLocation);
            var expectedToolExecutableName = $"{name}.dll";

            if (isDevelopmentLocation)
            {
                // Locating the correct development build to use is a little tricky.  Complications come from
                // 1) We don't know if the Debug or Release build is desired.  To overcome this we will pick whichever was modified most recently

                var topLevel = il2CppFolder;
                if (customRoot != null)

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Rebuild the tool so outputs land in the recognized published layout (bin/<config>/<tfm>/publish/<BinaryDirectoryForPlatform>).
  2. Confirm the TFM folder name matches what the toolchain emits.
  3. If the layout legitimately changed, update BinaryDirectoryForPlatform / the candidate match logic in IL2CPPUtils to recognize the new structure.

Example fix

/* no source edit */
// before: outputs at bin/Release/net8.0/<unknown>/il2cpp.exe (unrecognized)
// after: publish with bee so output lands at
//   bin/Release/net8.0/publish/<BinaryDirectoryForPlatform(platform)>/il2cpp.exe
Defensive patterns

Strategy: validation

Validate before calling

// After collecting candidates, verify at least one matches a recognized layout
bool recognized = candidates.Any(c =>
    c.Parent.Parent.Parent.FileName == "bin" ||
    (c.Parent.FileName == "publish" && c.Parent.Parent.FileName == expectedPublishDirectoryName));
if (!recognized) throw new InvalidOperationException("IL2CPP tool output layout unrecognized; rebuild with the published layout.");

Prevention

When it happens

Trigger: Dev IL2CPP location has built outputs but in an unrecognized TFM/publish layout; a toolchain layout refactor moved outputs into a third structure that this logic intentionally ignores.

Common situations: Upgrading the IL2CPP source tree to a version whose build output layout differs; a new TFM (e.g. net10.0) whose path depth differs; publish artifacts present but under an unexpected platform directory name.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/d3ef583dfbd9e2ac. Report an issue: GitHub.