Unity-Technologies/UnityCsReference · error · FileNotFoundException

The specified assembly file could not be found.

Error message

The specified assembly file could not be found.

What it means

Thrown by MethodEvaluator.Eval when the assemblyFile argument does not exist on disk (File.Exists is false). Eval loads the assembly via CurrentAssemblies.LoadFromPath and evaluates a static method in it, so a missing assembly is fatal.

Source

Thrown at Editor/Mono/Macros/MethodEvaluator.cs:111

                    {
                        var assembly = CurrentAssemblies.LoadFromPath(dllPath);
                        if (assembly != null && Array.Exists(assembly.GetTypes(), t => t.Name == args.Name))
                            return assembly;
                    }
                    catch (Exception)
                    {
                    }
                }
                return null;
            }
        }

        public static object Eval(string assemblyFile, string typeName,
            string methodName, Type[] paramTypes, object[] args)
        {
            if (!File.Exists(assemblyFile))
            {
                throw new FileNotFoundException("The specified assembly file could not be found.", assemblyFile);
            }
            var assemblyDirectory = Path.GetDirectoryName(assemblyFile);
            // AssemblyResolve may be called from the context of Default AssemblyLoadContext
            // That breaks Code Reload on CoreCLR
            var assembly = CurrentAssemblies.LoadFromPath(assemblyFile);
            var method = assembly.GetType(typeName, true).GetMethod(methodName,
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
                null, paramTypes, null);
            if (method == null)
                throw new ArgumentException(string.Format(
                    "Method {0}.{1}({2}) not found in assembly {3}!", typeName,
                    methodName, ToCommaSeparatedString(paramTypes),
                    assembly.FullName));
            return method.Invoke(null, args);
        }

        private static Type TypeOrTypeName(object o)
        {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Resolve the assembly path from a known-good location (e.g. the compiled ScriptAssemblies folder) right before evaluation.
  2. Verify File.Exists(assemblyFile) and log the absolute path before calling Eval.
  3. Ensure the target assembly compiled successfully; rebuild if the DLL is absent.

Example fix

// before
MethodEvaluator.Eval(assemblyFile, typeName, methodName, paramTypes, args);

// after
if (!File.Exists(assemblyFile))
    throw new FileNotFoundException($"Assembly missing: {assemblyFile}");
MethodEvaluator.Eval(assemblyFile, typeName, methodName, paramTypes, args);
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(assemblyFile)) throw new System.IO.FileNotFoundException($"Assembly missing: {assemblyFile}");

Try / catch

try { MethodEvaluator.Eval(assemblyFile, ...); }
catch (FileNotFoundException ex) { Debug.LogError($"Rebuild target assembly: {ex.FileName}"); }

Prevention

When it happens

Trigger: Macro evaluation or external code execution that targets an assembly path which is stale, relative to the wrong directory, or points to an assembly that failed to compile. Also a path with incorrect casing or forward/backslash mismatch.

Common situations: Editor macros evaluated after a code reload where the expected assembly path changed (e.g. Player vs Editor assemblies, or ScriptAssemblies output moved). A build pipeline passing a precompiled assembly path that no longer exists.

Related errors


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