{"record":{"id":"20ba2aba8325986a","repo":"Unity-Technologies/UnityCsReference","slug":"il2cpp-doesn-t-support-building-with-apicompatibi","errorCode":null,"errorMessage":"IL2CPP doesn't support building with {apiCompatibilityLevel} API compatibility level!","messagePattern":"IL2CPP doesn't support building with (.+?) API compatibility level!","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs","lineNumber":464,"sourceCode":"        }\n\n        internal static string[] GetBuilderDefinedDefines(BuildTarget target, ApiCompatibilityLevel apiCompatibilityLevel, bool enableIl2CppDebugger)\n        {\n            List<string> defines = new List<string>();\n\n            switch (apiCompatibilityLevel)\n            {\n                case ApiCompatibilityLevel.NET_Unity_4_8:\n                case ApiCompatibilityLevel.NET_Standard:\n                    // CORECLR_FIXME - .NET Should have a different set of defines\n#pragma warning disable CS0618\n                case ApiCompatibilityLevel.NET:\n#pragma warning restore CS0618\n                    defines.AddRange(BaseDefines46);\n                    break;\n\n                default:\n                    throw new InvalidOperationException($\"IL2CPP doesn't support building with {apiCompatibilityLevel} API compatibility level!\");\n            }\n\n            if (target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64 ||\n                target == BuildTarget.XboxOne || target == BuildTarget.WSAPlayer)\n            {\n                defines.AddRange(BaseDefinesWindows);\n\n                if (target == BuildTarget.WSAPlayer)\n                {\n                    defines.Add(\"WINAPI_FAMILY=WINAPI_FAMILY_APP\");\n                }\n                else\n                {\n                    defines.Add(\"WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP\");\n                }\n            }\n\n            if (enableIl2CppDebugger)","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs#L446-L482","documentation":"Thrown inside the switch that selects IL2CPP #defines for a given ApiCompatibilityLevel. Only NET_Unity_4_8, NET_Standard, and the deprecated NET case are handled; any other compatibility level falls through to default and throws InvalidOperationException, because IL2CPP has no defined base #define set for that level.","triggerScenarios":"Calling the IL2CPP define-builder (GetBuilderDefinedDefines) with an ApiCompatibilityLevel outside the supported set, e.g. NET_2_0, NET_2_0_Subset, NET_Web, or a custom/legacy level, while targeting an IL2CPP backend.","commonSituations":"A project migrated from an old Mono/.NET 2.0 Subset setup that retains a legacy ApiCompatibilityLevel after switching the backend to IL2CPP; programmatic define generation invoked with an enum value no longer supported by IL2CPP.","solutions":["Switch Player Settings > Api Compatibility Level to '.NET Standard 2.1' or '.NET Framework 4.x' (NET_Unity_4_8), both supported by IL2CPP.","Validate the compatibility level against the supported set before invoking the IL2CPP define builder.","If scripting a custom build, normalize the level to NET_Standard or NET_Unity_4_8 explicitly."],"exampleFix":"// before\nvar defines = GetBuilderDefinedDefines(target, apiCompatibilityLevel, enableDebugger);\n\n// after\nvar supported = apiCompatibilityLevel == ApiCompatibilityLevel.NET_Standard\n             || apiCompatibilityLevel == ApiCompatibilityLevel.NET_Unity_4_8;\nif (!supported) throw new InvalidOperationException(\"Switch API Compatibility Level to .NET Standard or .NET 4.x before building IL2CPP.\");\nvar defines = GetBuilderDefinedDefines(target, apiCompatibilityLevel, enableDebugger);","handlingStrategy":"validation","validationCode":"static readonly HashSet<ApiCompatibilityLevel> Il2CppSupported = new()\n{\n    ApiCompatibilityLevel.NET_Unity_4_8,\n    ApiCompatibilityLevel.NET_Standard,\n#pragma warning disable CS0618\n    ApiCompatibilityLevel.NET\n#pragma warning restore CS0618\n};\nif (!Il2CppSupported.Contains(apiCompatibilityLevel))\n    throw new InvalidOperationException(\"Set API Compatibility Level to .NET Standard or .NET 4.x for IL2CPP.\");","typeGuard":"static bool IsIl2CppSupported(ApiCompatibilityLevel l) =>\n    l == ApiCompatibilityLevel.NET_Unity_4_8 ||\n    l == ApiCompatibilityLevel.NET_Standard ||\n#pragma warning disable CS0618\n    l == ApiCompatibilityLevel.NET;","tryCatchPattern":null,"preventionTips":["Before invoking IL2CPP define generation, verify the compatibility level is in the supported set.","Standardize project Player Settings to .NET Standard 2.1 for IL2CPP builds."],"tags":["il2cpp","build-pipeline","api-compatibility","scripting-defines"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}