{"record":{"id":"199cc62d43c93b63","repo":"Unity-Technologies/UnityCsReference","slug":"both-excludeplatforms-and-includeplatforms-are","errorCode":null,"errorMessage":"Both 'excludePlatforms' and 'includePlatforms' are set.","messagePattern":"Both 'excludePlatforms' and 'includePlatforms' are set\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/ScriptCompilation/CustomScriptAssembly.cs","lineNumber":128,"sourceCode":"            UnityEngine.JsonUtility.FromJsonOverwrite(json, assemblyData);\n\n            UpdateRenamedReferences(assemblyData);\n            assemblyData.UpdateLegacyData();\n\n            if (assemblyData == null)\n                throw new System.Exception(\"Json file does not contain an assembly definition\");\n\n            return assemblyData;\n        }\n\n        public void ValidateFields()\n        {\n            if (string.IsNullOrEmpty(name))\n                throw new System.Exception(\"Required property 'name' not set\");\n\n            if ((excludePlatforms != null && excludePlatforms.Length > 0) &&\n                (includePlatforms != null && includePlatforms.Length > 0))\n                throw new System.Exception(\"Both 'excludePlatforms' and 'includePlatforms' are set.\");\n\n            if (autoReferenced && UnityCodeGenHelpers.IsCodeGen(name))\n            {\n                throw new Exception($\"Assembly '{name}' is a CodeGen assembly and cannot be Auto Referenced\");\n            }\n        }\n\n        public static string ToJson(CustomScriptAssemblyData data)\n        {\n            return UnityEngine.JsonUtility.ToJson(data, true);\n        }\n\n        static void UpdateRenamedReferences(CustomScriptAssemblyData data)\n        {\n            if (data.references == null || data.references.Length == 0)\n                return;\n\n            HashSet<string> additionalReferences = null;","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/CustomScriptAssembly.cs#L110-L146","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (.asmdef)\n{\n    \"name\": \"MyAssembly\",\n    \"includePlatforms\": [\"Android\", \"iOS\"],\n    \"excludePlatforms\": [\"Windows\"]\n}\n// after (include-only model)\n{\n    \"name\": \"MyAssembly\",\n    \"includePlatforms\": [\"Android\", \"iOS\"],\n    \"excludePlatforms\": []\n}","handlingStrategy":"validation","validationCode":"// Validate asmdef data before it reaches ValidateFields()\nbool HasMutuallyExclusivePlatforms(string[] include, string[] exclude)\n    => (include != null && include.Length > 0)\n       && (exclude != null && exclude.Length > 0);\n\n// usage before serializing/saving an asmdef\nif (HasMutuallyExclusivePlatforms(data.includePlatforms, data.excludePlatforms))\n    throw new InvalidOperationException(\n        \"Choose includePlatforms OR excludePlatforms, not both.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["unity","asmdef","script-compilation","platforms","config"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}