{"record":{"id":"bc843af073a0fe64","repo":"Unity-Technologies/UnityCsReference","slug":"compilecsharp-is-no-longer-supported-use-unityedi","errorCode":null,"errorMessage":"CompileCSharp is no longer supported. Use UnityEditor.Compilation.AssemblyBuilder instead.","messagePattern":"CompileCSharp is no longer supported\\. Use UnityEditor\\.Compilation\\.AssemblyBuilder instead\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorUtility.cs","lineNumber":372,"sourceCode":"\n            if (editor.inspectorMode != InspectorMode.Normal)\n                return false;\n\n            return IsHiddenInInspector(editor.target);\n        }\n\n        internal static bool IsHiddenInInspector(UnityEngine.Object target)\n        {\n            if (!target)\n                return true;\n\n            return (target.hideFlags & HideFlags.HideInInspector) == HideFlags.HideInInspector;\n        }\n\n        [Obsolete(message: \"Use UnityEditor.Compilation.AssemblyBuilder instead\", error: true)]\n        public static string[] CompileCSharp(string[] scripts, string[] references, string[] defines, string outputAssembly)\n        {\n            throw new NotSupportedException(\"CompileCSharp is no longer supported. Use UnityEditor.Compilation.AssemblyBuilder instead.\");\n        }\n\n        [Obsolete(\"Use PrefabUtility.InstantiatePrefab\", false)]\n        public static Object InstantiatePrefab(Object target)\n        {\n            return PrefabUtility.InstantiatePrefab(target);\n        }\n\n        [Obsolete(\"Use PrefabUtility.SaveAsPrefabAsset with a path instead.\", false)]\n        public static GameObject ReplacePrefab(GameObject go, Object targetPrefab, ReplacePrefabOptions options)\n        {\n            return PrefabUtility.ReplacePrefab(go, targetPrefab, options);\n        }\n\n        [Obsolete(\"Use PrefabUtility.SaveAsPrefabAsset or PrefabUtility.SaveAsPrefabAssetAndConnect with a path instead.\", false)]\n        public static GameObject ReplacePrefab(GameObject go, Object targetPrefab)\n        {\n            return PrefabUtility.ReplacePrefab(go, targetPrefab, ReplacePrefabOptions.Default);","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorUtility.cs#L354-L390","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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().","If you only needed to compile generated source, write the files to disk first and let AssemblyBuilder reference them by path.","Subscribe to AssemblyBuilder.buildFinished to get success/failure instead of the old synchronous return.","Remove all references to EditorUtility.CompileCSharp so the compile-time Obsolete error clears."],"exampleFix":"// before\nstring[] asm = EditorUtility.CompileCSharp(scripts, refs, defines, outPath);\n// after\nvar builder = new UnityEditor.Compilation.AssemblyBuilder(outPath, scripts);\nbuilder.additionalReferences = refs;\nbuilder.scriptingDefines = defines;\nbuilder.buildFinished += (b, success) => { /* ... */ };\nbuilder.Build();","handlingStrategy":"validation","validationCode":"// CompileCSharp is hard-deprecated; switch to AssemblyBuilder at the call site.\nvar builder = new UnityEditor.Compilation.AssemblyBuilder(outputAssembly, scripts);\nbuilder.additionalReferences = references;\nbuilder.scriptingDefines = defines;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Search the codebase for 'CompileCSharp' and remove every reference so the compile-time Obsolete(error:true) clears.","Prefer AssemblyBuilder.buildFinished for asynchronous completion instead of a synchronous return.","When porting legacy samples, rewrite the compile step rather than suppressing the obsolete error."],"tags":["obsolete","deprecated","compilation","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}