{"record":{"id":"83b173b4ed91112b","repo":"Unity-Technologies/UnityCsReference","slug":"standalonesubtarget-is-not-a-valid-subtarget-f","errorCode":null,"errorMessage":"'{standaloneSubtarget}' is not a valid subtarget for the Standalone build target","messagePattern":"'(.+?)' is not a valid subtarget for the Standalone build target","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/BuildPipeline/NamedBuildTarget.cs","lineNumber":192,"sourceCode":"            }\n\n            return NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);\n        }\n\n        internal static NamedBuildTarget FromTargetAndSubtarget(BuildTarget target, int subtarget)\n        {\n            var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);\n            if (buildTargetGroup == BuildTargetGroup.Standalone)\n            {\n                var standaloneSubtarget = (StandaloneBuildSubtarget)subtarget;\n                switch (standaloneSubtarget)\n                {\n                    case StandaloneBuildSubtarget.Player:\n                        return NamedBuildTarget.Standalone;\n                    case StandaloneBuildSubtarget.Server:\n                        return NamedBuildTarget.Server;\n                    default:\n                        throw new ArgumentException($\"'{standaloneSubtarget}' is not a valid subtarget for the Standalone build target\");\n                }\n            }\n\n            return NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);\n        }\n\n        [ExcludeFromDocs]\n        public static bool operator==(NamedBuildTarget lhs, NamedBuildTarget rhs)\n        {\n            return lhs.Equals(rhs);\n        }\n\n        [ExcludeFromDocs]\n        public static bool operator!=(NamedBuildTarget lhs, NamedBuildTarget rhs)\n        {\n            return !lhs.Equals(rhs);\n        }\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/BuildPipeline/NamedBuildTarget.cs#L174-L210","documentation":"When resolving a NamedBuildTarget for a Standalone target from a subtarget integer, only Player and Server are accepted. Any other StandaloneBuildSubtarget enum value hits the default case and throws ArgumentException.","triggerScenarios":"Calling the internal GetNamedBuildTarget(target, subtarget) where the target is in the Standalone group and the subtarget integer casts to a StandaloneBuildSubtarget value other than Player (0) or Server (1).","commonSituations":"A future StandaloneBuildSubtarget enum member added without updating this switch; passing a raw subtarget integer that does not correspond to a valid member; platform extension injecting a custom standalone subtarget.","solutions":["Ensure the subtarget passed is StandaloneBuildSubtarget.Player or StandaloneBuildSubtarget.Server.","If a new subtarget was added, extend the switch to map it to a NamedBuildTarget.","Use NamedBuildTarget.FromActiveSettings(target) which derives the correct subtarget from active settings."],"exampleFix":"// before\nvar nbt = NamedBuildTargetInternal.GetNamedBuildTarget(target, rawSubtarget);\n\n// after\nvar sub = (StandaloneBuildSubtarget)rawSubtarget;\nif (sub != StandaloneBuildSubtarget.Player && sub != StandaloneBuildSubtarget.Server)\n    throw new ArgumentOutOfRangeException(nameof(rawSubtarget), sub, \"Only Player/Server standalone subtargets are supported.\");\nvar nbt = NamedBuildTargetInternal.GetNamedBuildTarget(target, rawSubtarget);","handlingStrategy":"validation","validationCode":"var sub = (StandaloneBuildSubtarget)subtarget;\nif (sub != StandaloneBuildSubtarget.Player && sub != StandaloneBuildSubtarget.Server)\n    throw new ArgumentOutOfRangeException(nameof(subtarget), sub, \"Only Player/Server subtargets are valid for Standalone.\");","typeGuard":"static bool IsValidStandaloneSubtarget(int sub) =>\n    Enum.IsDefined(typeof(StandaloneBuildSubtarget), sub) &&\n    ((StandaloneBuildSubtarget)sub is StandaloneBuildSubtarget.Player or StandaloneBuildSubtarget.Server);","tryCatchPattern":null,"preventionTips":["Only pass Player or Server subtargets for Standalone builds.","Use FromActiveSettings(target) to avoid manual subtarget handling."],"tags":["named-build-target","standalone","subtarget","build-pipeline"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}