{"record":{"id":"85cfa5699ccbc69f","repo":"Unity-Technologies/UnityCsReference","slug":"value-is-not-valid-in-the-expression","errorCode":null,"errorMessage":"'{value}' is not valid in the expression","messagePattern":"'(.+?)' is not valid in the expression","errorType":"exception","errorClass":"ExpressionNotValidException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/ScriptCompilation/VersionRanges.cs","lineNumber":171,"sourceCode":"            if (begin > end)\n            {\n                return null;\n            }\n\n            int count = 0;\n            while (newBegin <= end)\n            {\n                var value = expression[newBegin];\n\n                if (value == ',')\n                {\n                    newBegin++;\n                    break;\n                }\n\n                if (!versionTypeTraits.IsAllowedCharacter(value) && value != '*')\n                {\n                    throw new ExpressionNotValidException($\"'{value}' is not valid in the expression\");\n                }\n\n                count++;\n                newBegin++;\n            }\n\n            return expression.Substring(begin, count);\n        }\n\n        private struct ExpressionParsedData\n        {\n            public TVersion leftVersion;\n            public TVersion rightVersion;\n            public ExpressionTypeKey GenerateExpressionTypeKey;\n        }\n    }\n}\n","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/VersionRanges.cs#L153-L189","documentation":"Thrown inside PopVersionString (VersionRanges.cs:171) while scanning a version-number token (between delimiters or around the comma separator) when a character is neither an allowed version character per IVersionTypeTraits.IsAllowedCharacter (digits, letters, '.', '-', and '/' for UnityVersion; digits, letters, '.', '-' for SemVersion) nor the wildcard '*'. NOTE: the exception message contains only the single offending character, not the whole expression, which makes it harder to locate.","triggerScenarios":"A disallowed character inside a version token: '_', '+', space, '<', '>', '=', '@', '~', etc. The single most common case is a SPACE AFTER THE COMMA inside a range ('[1.0, 2.0]') — the right-side scan hits the space, which is neither an allowed char nor '*', so it throws with value=' '. Also '1.0_2', '1.0+build', '~1.0', '1.0@2'.","commonSituations":"Typing '[1.0, 2.0]' with a space after the comma (the Define-Constraints trimmer does not trim interior spaces); appending SemVer build metadata '1.0+001' (not supported by this tokenizer); using an underscore inside a pre-release tag.","solutions":["Remove interior whitespace: '[1.0, 2.0]' -> '[1.0,2.0]'.","Drop unsupported characters from version tokens: '1.0_2' -> '1.0.2'; strip '+build'.","Keep only allowed characters (digits, letters, '.', '-', '/', and the '*' wildcard) inside version tokens.","If you need a wildcard, use '*' as a body character (e.g. '[1.0,2.*]'); it is the only non-trait character permitted in the token body."],"exampleFix":"// before\n\"[1.0, 2.0]\"   // or \"1.0_2\"  or \"[1.0,2.0+rc1]\"\n// after\n\"[1.0,2.0]\"    // or \"1.0.2\"  or \"[1.0,2.0]\"","handlingStrategy":"validation","validationCode":"// Version-token body chars: digit, letter, '.', '-', '/', and '*' wildcard.\n// Reject interior whitespace and punctuation BEFORE parsing.\nstatic readonly char[] k_AllowedBodyExtras = { '.', '-', '/', '*' };\nstatic bool BodyHasOnlyAllowedChars(string expr) {\n    if (string.IsNullOrEmpty(expr)) return false;\n    foreach (var c in expr) {\n        if (c == ',' || c == '[' || c == ']' || c == '(' || c == ')') continue;\n        if (char.IsDigit(c) || char.IsLetter(c)) continue;\n        if (System.Array.IndexOf(k_AllowedBodyExtras, c) >= 0) continue;\n        if (char.IsWhiteSpace(c)) return false;  // interior space — the #1 cause\n        return false;\n    }\n    return true;\n}\n// Strongest check: run the full k_ValidRange regex, which has no interior spaces.","typeGuard":"static bool HasNoInteriorSpaces(string e) =>\n    !string.IsNullOrEmpty(e) && !e.Contains(\" \") && !e.Contains(\"\\t\");","tryCatchPattern":"// NOTE: ex.Message contains ONLY the offending char, not the expression.\n// Log the expression yourself for context.\ntry { var def = ranges.GetExpression(expr); }\ncatch (ExpressionNotValidException ex) {\n    ReportToUser($\"{expr}: character '{ex.Message}' is not allowed in a version token.\");\n}","preventionTips":["Never put a space after the comma inside a range: write '[1.0,2.0]', not '[1.0, 2.0]'.","Strip SemVer build metadata ('+001') and underscores from version tokens before use.","Remember the message reports only the bad char — always log the full expression alongside it.","Use '*' only inside a token body, never as the whole token."],"tags":["unity","asmdef","version-range","script-compilation","parsing"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}