Unity-Technologies/UnityCsReference · error · NotSupportedException

GetIl2CppBclDistributionDirectory is only supported for IL2C

Error message

GetIl2CppBclDistributionDirectory is only supported for IL2CPP with the NET profile.

What it means

Thrown by GetIl2CppBclDistributionDirectory when the active scripting backend is IL2CPP but the API compatibility level is not ApiCompatibilityLevel.NET. The IL2CPP Base Class Library (BCL) distribution directory lookup is meaningful only for the legacy .NET profile; for other profiles (e.g. .NET Standard, .NET 4.x sub-levels) there is no single BCL distribution folder to return.

Source

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

                Path.Combine(GetIl2CppBclDistributionDirectory(target, namedTarget, buildOptions), "lib");
            if (Directory.Exists(libDirectory))
                result.Add(libDirectory);
            else
                Debug.LogError($"Unable to find il2cpp bcl directory: {libDirectory}");
            return result;
        }

        internal static string GetIl2CppBclDistributionDirectory(BuildTarget target, BuildOptions buildOptions)
        {
            var namedTarget = NamedBuildTarget.FromActiveSettings(target);
            return GetIl2CppBclDistributionDirectory(target, namedTarget, buildOptions);
        }

        static string GetIl2CppBclDistributionDirectory(BuildTarget target, NamedBuildTarget namedTarget, BuildOptions buildOptions)
        {
#pragma warning disable CS0618
            if (PlayerSettings.GetApiCompatibilityLevel(namedTarget) != ApiCompatibilityLevel.NET)
                throw new NotSupportedException($"{nameof(GetIl2CppBclDistributionDirectory)} is only supported for IL2CPP with the NET profile.");
#pragma warning restore CS0618

            var gotBuildTarget = BuildTargetDiscovery.TryGetBuildTarget(target, out var ibuildTarget);
            if (!gotBuildTarget || ibuildTarget.ScriptingPlatformProperties == null)
            {
                return null;
            }
            return Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(target, buildOptions, false), ibuildTarget.ScriptingPlatformProperties.IL2CPPBCLDirectory);
        }

        internal static string[] GetBuilderDefinedDefines(BuildTarget target, ApiCompatibilityLevel apiCompatibilityLevel, bool enableIl2CppDebugger)
        {
            List<string> defines = new List<string>();

            switch (apiCompatibilityLevel)
            {
                case ApiCompatibilityLevel.NET_Unity_4_8:
                case ApiCompatibilityLevel.NET_Standard:

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Set Player Settings > Other > Api Compatibility Level to '.NET' (ApiCompatibilityLevel.NET) for the target group before invoking this method.
  2. Guard the call: only call GetIl2CppBclDistributionDirectory when GetApiCompatibilityLevel(namedTarget) == ApiCompatibilityLevel.NET.
  3. If you need BCL info for .NET Standard, use the IL2CPP toolchain paths specific to that TFM rather than this method.

Example fix

// before
var dir = Il2CppBuildPipelineExtensions.GetIl2CppBclDistributionDirectory(target, buildOptions);

// after
var namedTarget = NamedBuildTarget.FromActiveSettings(target);
#pragma warning disable CS0618
if (PlayerSettings.GetApiCompatibilityLevel(namedTarget) == ApiCompatibilityLevel.NET)
#pragma warning restore CS0618
{
    var dir = Il2CppBuildPipelineExtensions.GetIl2CppBclDistributionDirectory(target, buildOptions);
}
Defensive patterns

Strategy: validation

Validate before calling

var namedTarget = NamedBuildTarget.FromActiveSettings(target);
#pragma warning disable CS0618
bool canCall = PlayerSettings.GetApiCompatibilityLevel(namedTarget) == ApiCompatibilityLevel.NET;
#pragma warning restore CS0618
if (!canCall) return null; // or surface a user-facing message

Prevention

When it happens

Trigger: Calling GetIl2CppBclDistributionDirectory(target, buildOptions) while PlayerSettings.GetApiCompatibilityLevel(namedTarget) returns anything other than ApiCompatibilityLevel.NET (e.g. NET_Standard, NET_Unity_4_8 used in a non-IL2CPP path, or Level2/Level3 subset levels).

Common situations: A custom build pipeline or editor script invokes this helper expecting it to work for any IL2CPP build; project Player Settings have been set to .NET Standard 2.1 or a .NET subset instead of the full .NET profile; upgrading a project where the API compatibility level defaulted to a non-NET value.

Related errors


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