Unity-Technologies/UnityCsReference · error · Exception
Both 'excludePlatforms' and 'includePlatforms' are set.
Error message
Both 'excludePlatforms' and 'includePlatforms' are set.
What it means
Thrown by CustomScriptAssemblyData.ValidateFields() (CustomScriptAssembly.cs:128) when an assembly definition (.asmdef) data object has both a non-empty 'includePlatforms' array AND a non-empty 'excludePlatforms' array. Unity treats these two as mutually exclusive: you either whitelist the platforms the assembly compiles for (include) or blacklist the ones it skips (exclude), never both. The check fires during JSON deserialization validation, so it surfaces at asset-import / assembly-graph-build time.
Source
Thrown at Editor/Mono/Scripting/ScriptCompilation/CustomScriptAssembly.cs:128
UnityEngine.JsonUtility.FromJsonOverwrite(json, assemblyData);
UpdateRenamedReferences(assemblyData);
assemblyData.UpdateLegacyData();
if (assemblyData == null)
throw new System.Exception("Json file does not contain an assembly definition");
return assemblyData;
}
public void ValidateFields()
{
if (string.IsNullOrEmpty(name))
throw new System.Exception("Required property 'name' not set");
if ((excludePlatforms != null && excludePlatforms.Length > 0) &&
(includePlatforms != null && includePlatforms.Length > 0))
throw new System.Exception("Both 'excludePlatforms' and 'includePlatforms' are set.");
if (autoReferenced && UnityCodeGenHelpers.IsCodeGen(name))
{
throw new Exception($"Assembly '{name}' is a CodeGen assembly and cannot be Auto Referenced");
}
}
public static string ToJson(CustomScriptAssemblyData data)
{
return UnityEngine.JsonUtility.ToJson(data, true);
}
static void UpdateRenamedReferences(CustomScriptAssemblyData data)
{
if (data.references == null || data.references.Length == 0)
return;
HashSet<string> additionalReferences = null;View on GitHub (pinned to 225b0fbdb5)
Solutions
- Open the offending .asmdef and delete one of the two arrays entirely (or set it to an empty array "" so it is treated as unset). Keep includePlatforms to compile only for listed targets, or keep excludePlatforms to compile for all except the listed ones.
- If you intended the assembly for all platforms, remove both arrays so it defaults to all-platforms.
- In the Inspector, the asmdef platform UI uses a single control (Include / Exclude toggle); switch the mode there and Unity will clear the unused array automatically rather than hand-editing JSON.
Example fix
// before (.asmdef)
{
"name": "MyAssembly",
"includePlatforms": ["Android", "iOS"],
"excludePlatforms": ["Windows"]
}
// after (include-only model)
{
"name": "MyAssembly",
"includePlatforms": ["Android", "iOS"],
"excludePlatforms": []
} Defensive patterns
Strategy: validation
Validate before calling
// Validate asmdef data before it reaches ValidateFields()
bool HasMutuallyExclusivePlatforms(string[] include, string[] exclude)
=> (include != null && include.Length > 0)
&& (exclude != null && exclude.Length > 0);
// usage before serializing/saving an asmdef
if (HasMutuallyExclusivePlatforms(data.includePlatforms, data.excludePlatforms))
throw new InvalidOperationException(
"Choose includePlatforms OR excludePlatforms, not both."); Prevention
- Author asmdef platform settings through the Inspector's single Include/Exclude control so the unused array is cleared automatically.
- When scripting asmdef edits, always clear the opposite array before writing the JSON.
- Add a pre-commit lint step that rejects asmdefs where both platform arrays are non-empty.
When it happens
Trigger: A .asmdef JSON object containing both "includePlatforms": ["Android","iOS"] and "excludePlatforms": ["Windows"] with at least one entry in each. Manually editing the .asmdef by hand and leaving both arrays populated. Copying an asmdef that used one model and then partially switching to the other without clearing the original.
Common situations: Migrating from the legacy exclude-everything-but model to the include model and forgetting to null/empty the old array. Bulk editing many asmdefs with a script that sets includePlatforms without clearing excludePlatforms. Tooling that round-trips asmdef JSON and re-serializes both fields.
Related errors
- Platform name '{0}' not supported. Supported platform names:
- Invalid Define Constraint: "{DefineConstraints[i]}" at line
- Assembly has duplicate references: {duplicateRefsString}
- Folder '{loadedCustomScriptAssemblyReference.PathPrefix}' co
- Assembly cannot be have reserved name '{loadedCustomScriptAs
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/199cc62d43c93b63.
Report an issue: GitHub.