Unity-Technologies/UnityCsReference · error · NotSupportedException

CompileCSharp is no longer supported. Use UnityEditor.Compil

Error message

CompileCSharp is no longer supported. Use UnityEditor.Compilation.AssemblyBuilder instead.

What it means

CompileCSharp is marked [Obsolete(..., error: true)], so referencing it is a hard compile error; the body also throws NotSupportedException at runtime as a belt-and-suspenders guard. Unity removed in-process C# compilation in favour of UnityEditor.Compilation.AssemblyBuilder, which builds scripts through the normal compilation pipeline rather than a separate ad-hoc compiler invocation.

Source

Thrown at Editor/Mono/EditorUtility.cs:372

            if (editor.inspectorMode != InspectorMode.Normal)
                return false;

            return IsHiddenInInspector(editor.target);
        }

        internal static bool IsHiddenInInspector(UnityEngine.Object target)
        {
            if (!target)
                return true;

            return (target.hideFlags & HideFlags.HideInInspector) == HideFlags.HideInInspector;
        }

        [Obsolete(message: "Use UnityEditor.Compilation.AssemblyBuilder instead", error: true)]
        public static string[] CompileCSharp(string[] scripts, string[] references, string[] defines, string outputAssembly)
        {
            throw new NotSupportedException("CompileCSharp is no longer supported. Use UnityEditor.Compilation.AssemblyBuilder instead.");
        }

        [Obsolete("Use PrefabUtility.InstantiatePrefab", false)]
        public static Object InstantiatePrefab(Object target)
        {
            return PrefabUtility.InstantiatePrefab(target);
        }

        [Obsolete("Use PrefabUtility.SaveAsPrefabAsset with a path instead.", false)]
        public static GameObject ReplacePrefab(GameObject go, Object targetPrefab, ReplacePrefabOptions options)
        {
            return PrefabUtility.ReplacePrefab(go, targetPrefab, options);
        }

        [Obsolete("Use PrefabUtility.SaveAsPrefabAsset or PrefabUtility.SaveAsPrefabAssetAndConnect with a path instead.", false)]
        public static GameObject ReplacePrefab(GameObject go, Object targetPrefab)
        {
            return PrefabUtility.ReplacePrefab(go, targetPrefab, ReplacePrefabOptions.Default);

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Replace the call with UnityEditor.Compilation.AssemblyBuilder: construct it with the output assembly path, set the scripts/references/defines via its properties, then call Build().
  2. If you only needed to compile generated source, write the files to disk first and let AssemblyBuilder reference them by path.
  3. Subscribe to AssemblyBuilder.buildFinished to get success/failure instead of the old synchronous return.
  4. Remove all references to EditorUtility.CompileCSharp so the compile-time Obsolete error clears.

Example fix

// before
string[] asm = EditorUtility.CompileCSharp(scripts, refs, defines, outPath);
// after
var builder = new UnityEditor.Compilation.AssemblyBuilder(outPath, scripts);
builder.additionalReferences = refs;
builder.scriptingDefines = defines;
builder.buildFinished += (b, success) => { /* ... */ };
builder.Build();
Defensive patterns

Strategy: validation

Validate before calling

// CompileCSharp is hard-deprecated; switch to AssemblyBuilder at the call site.
var builder = new UnityEditor.Compilation.AssemblyBuilder(outputAssembly, scripts);
builder.additionalReferences = references;
builder.scriptingDefines = defines;

Prevention

When it happens

Trigger: Calling EditorUtility.CompileCSharp(scripts, references, defines, output) from any editor script, or having legacy code that compiled assemblies on the fly (e.g. old script-generation tooling). The Obsolete(error:true) attribute surfaces it at compile time.

Common situations: Porting an old Unity 4.x/5.x editor extension that generated and compiled C# at runtime. Copy-pasted sample code from pre-2017 forum answers. Build servers failing because a checked-in legacy script still references the removed API.

Related errors


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