{"record":{"id":"37cd99ee35600066","repo":"Unity-Technologies/UnityCsReference","slug":"targetname-is-not-a-valid-build-target-name","errorCode":null,"errorMessage":"'{targetName}' is not a valid build target name","messagePattern":"'(.+?)' is not a valid build target name","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildPipeline/NamedBuildTarget.cs","lineNumber":93,"sourceCode":"        public static readonly NamedBuildTarget Stadia = new NamedBuildTarget(\"Stadia\");\n        ///<summary>LinuxHeadlessSimulation.</summary>\n        public static readonly NamedBuildTarget LinuxHeadlessSimulation = new NamedBuildTarget(\"LinuxHeadlessSimulation\");\n        ///<summary>CloudRendering.</summary>\n        [System.Obsolete(\"CloudRendering is deprecated, please use LinuxHeadlessSimulation (UnityUpgradable) -> LinuxHeadlessSimulation\", false)]\n        public static readonly NamedBuildTarget CloudRendering = LinuxHeadlessSimulation;\n        ///<summary>EmbeddedLinux.</summary>\n        public static readonly NamedBuildTarget EmbeddedLinux  = new NamedBuildTarget(\"EmbeddedLinux\");\n        ///<summary>QNX.</summary>\n        public static readonly NamedBuildTarget QNX  = new NamedBuildTarget(\"QNX\");\n\n        ///<summary>Name of the build target.</summary>\n        public string TargetName { get; }\n\n        internal NamedBuildTarget(string targetName)\n        {\n            if (!k_ValidNames.Contains(targetName))\n            {\n                throw new ArgumentException($\"'{targetName}' is not a valid build target name\");\n            }\n\n            TargetName = targetName;\n        }\n\n        ///<summary>Returns the appropriate BuildTargetGroup that corresponds to the specified NamedBuildTarget.</summary>\n        ///<param name=\"namedBuildTarget\">Named build target.</param>\n        public BuildTargetGroup ToBuildTargetGroup()\n        {\n            switch (TargetName)\n            {\n                case \"Server\":\n                    return BuildTargetGroup.Standalone;\n                default:\n                    return BuildPipeline.GetBuildTargetGroupByName(TargetName);\n            }\n        }\n","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildPipeline/NamedBuildTarget.cs#L75-L111","documentation":"NamedBuildTarget's constructor rejects any target name not present in the internal k_ValidNames set. This guards construction of the named build target singletons; passing an arbitrary or misspelled string violates the closed set of supported names.","triggerScenarios":"Calling `new NamedBuildTarget(targetName)` with a string that is not in k_ValidNames (e.g. a typo, a deprecated name, or a custom platform string not registered).","commonSituations":"Code that constructs a NamedBuildTarget dynamically from user input or config; referencing a build target name that existed in an older Unity version but was renamed/removed; serialization desync where a stored name is stale.","solutions":["Use the predefined static NamedBuildTarget fields (Standalone, iOS, Android, PS5, etc.) instead of constructing from a string.","If you must construct from a string, validate against k_ValidNames (or the public TargetName list) first.","Correct the misspelled/deprecated name to the current canonical name."],"exampleFix":"// before\nvar t = new NamedBuildTarget(\"iphone\"); // not a valid name\n\n// after\nvar t = NamedBuildTarget.iOS; // canonical, valid","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> ValidNames = new() { \"Standalone\",\"Server\",\"iOS\",\"Android\",\"PS4\",\"PS5\",\"XboxOne\",\"GameCoreScarlett\",\"GameCoreXboxOne\",\"EmbeddedLinux\",\"QNX\",\"Kepler\",\"WebGL\",\"tvOS\" };\nif (!ValidNames.Contains(targetName))\n    throw new ArgumentException($\"'{targetName}' is not a known NamedBuildTarget name.\");","typeGuard":"static bool IsValidNamedBuildTargetName(string name) => ValidNames.Contains(name);","tryCatchPattern":null,"preventionTips":["Prefer the static NamedBuildTarget singletons over constructing from strings.","Validate dynamic target-name input against the canonical name set before construction."],"tags":["named-build-target","validation","build-pipeline"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}