{"record":{"id":"bb2e6ccd5687c695","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-define-constraint-defineconstraints-i","errorCode":null,"errorMessage":"Invalid Define Constraint: \"{DefineConstraints[i]}\" at line {(i+1).ToString()}","messagePattern":"Invalid Define Constraint: \"(.+?)\" at line (.+?)","errorType":"exception","errorClass":"AssemblyDefinitionException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/ScriptCompilation/CustomScriptAssembly.cs","lineNumber":556,"sourceCode":"            var isTestFrameworkAssembly = DefineConstraints != null && Array.Exists(DefineConstraints, x => x == \"UNITY_TESTS_FRAMEWORK\");\n            if (!buildingForEditor && (isTestAssembly || isTestFrameworkAssembly) && !isBuildingWithTestAssemblies)\n            {\n                return false;\n            }\n\n            if (symbolDefinitionContext.IsEmpty())\n            {\n                throw new ArgumentException(\"Defines cannot be empty\", nameof(symbolDefinitionContext));\n            }\n\n            // Log invalid define constraints\n            if (DefineConstraints != null)\n            {\n                for (var i = 0; i < DefineConstraints.Length; ++i)\n                {\n                    if (!DefineConstraintsHelper.IsDefineConstraintValid(DefineConstraints[i]))\n                    {\n                        throw new AssemblyDefinitionException($\"Invalid Define Constraint: \\\"{DefineConstraints[i]}\\\" at line {(i+1).ToString()}\", FilePath);\n                    }\n                }\n            }\n            symbolDefinitionContext.SetResponseFileDefines(ResponseFileDefines);\n            if (!DefineConstraintsHelper.IsDefineConstraintsCompatibleContext(symbolDefinitionContext, DefineConstraints))\n            {\n                return false;\n            }\n\n            if (isTestAssembly && AssetPathMetaData != null && !AssetPathMetaData.IsTestable)\n            {\n                return false;\n            }\n\n            // Compatible with editor and all platforms.\n            if (IncludePlatforms == null && ExcludePlatforms == null)\n            {\n                return true;","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/CustomScriptAssembly.cs#L538-L574","documentation":"Thrown while building an assembly's symbol-definition context (CustomScriptAssembly.cs:556) when an entry in the asmdef's defineConstraints array fails DefineConstraintsHelper.IsDefineConstraintValid. That helper splits each constraint on '|', trims whitespace, strips a single leading '!' (negation), and validates the remainder with SymbolNameRestrictions.IsValid. An entry is invalid if it is null, empty after trimming, or contains characters illegal in a define symbol. The reported 1-based line number is the index within the defineConstraints array, not a line in the file.","triggerScenarios":"An asmdef \"defineConstraints\" array containing an entry with illegal characters (spaces inside the symbol, hyphens, leading digits, or empty strings). Examples that fail: \"\", \" \", \"MY SYMBOL\", \"1FOO\", or a null entry.","commonSituations":"Typos when hand-editing constraints. Pasting constraints from documentation that uses human-readable labels instead of actual define symbols. Leaving an empty string from a template. Using lowercase with spaces like \"unity ios\".","solutions":["Inspect the defineConstraints entry at the 1-based index named in the message and correct it to a valid preprocessor-symbol name (uppercase letters, digits, underscores; must start with a letter/underscore).","Use the documented OR syntax with '||' (e.g. \"UNITY_IOS || UNITY_TVOS\") and negation with '!' (e.g. \"!UNITY_ANDROID\"); ensure no stray spaces inside a single symbol."],"exampleFix":"// before (.asmdef)\n\"defineConstraints\": [\"MY PLATFORM\", \"\"]\n// after\n\"defineConstraints\": [\"MY_PLATFORM\"]","handlingStrategy":"validation","validationCode":"// Validate a define constraint the same way IsDefineConstraintValid does\nstatic bool IsValidDefineConstraint(string c)\n{\n    if (c == null) return false;\n    foreach (var part in c.Split('|'))\n    {\n        var s = part.Trim().TrimStart('!');\n        // valid symbol: starts letter/_, letters/digits/_ only, non-empty\n        if (s.Length == 0) return false;\n        if (!(char.IsLetter(s[0]) || s[0] == '_')) return false;\n        foreach (var ch in s)\n            if (!(char.IsLetterOrDigit(ch) || ch == '_')) return false;\n    }\n    return true;\n}\n\nforeach (var c in data.defineConstraints ?? Array.Empty<string>())\n    if (!IsValidDefineConstraint(c))\n        throw new InvalidOperationException($\"Invalid define constraint: '{c}'\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only uppercase A-Z, digits, and underscores in define symbols.","Use '||' for OR and a leading '!' for negation; never put spaces inside a single symbol.","Lint defineConstraints entries against a symbol-name regex before committing asmdefs."],"tags":["unity","asmdef","script-compilation","define-constraints","config"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}