Unity-Technologies/UnityCsReference · error · ArgumentException
'{targetName}' is not a valid build target name
Error message
'{targetName}' is not a valid build target name What it means
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.
Source
Thrown at Editor/Mono/BuildPipeline/NamedBuildTarget.cs:93
public static readonly NamedBuildTarget Stadia = new NamedBuildTarget("Stadia");
///<summary>LinuxHeadlessSimulation.</summary>
public static readonly NamedBuildTarget LinuxHeadlessSimulation = new NamedBuildTarget("LinuxHeadlessSimulation");
///<summary>CloudRendering.</summary>
[System.Obsolete("CloudRendering is deprecated, please use LinuxHeadlessSimulation (UnityUpgradable) -> LinuxHeadlessSimulation", false)]
public static readonly NamedBuildTarget CloudRendering = LinuxHeadlessSimulation;
///<summary>EmbeddedLinux.</summary>
public static readonly NamedBuildTarget EmbeddedLinux = new NamedBuildTarget("EmbeddedLinux");
///<summary>QNX.</summary>
public static readonly NamedBuildTarget QNX = new NamedBuildTarget("QNX");
///<summary>Name of the build target.</summary>
public string TargetName { get; }
internal NamedBuildTarget(string targetName)
{
if (!k_ValidNames.Contains(targetName))
{
throw new ArgumentException($"'{targetName}' is not a valid build target name");
}
TargetName = targetName;
}
///<summary>Returns the appropriate BuildTargetGroup that corresponds to the specified NamedBuildTarget.</summary>
///<param name="namedBuildTarget">Named build target.</param>
public BuildTargetGroup ToBuildTargetGroup()
{
switch (TargetName)
{
case "Server":
return BuildTargetGroup.Standalone;
default:
return BuildPipeline.GetBuildTargetGroupByName(TargetName);
}
}
View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
var t = new NamedBuildTarget("iphone"); // not a valid name
// after
var t = NamedBuildTarget.iOS; // canonical, valid Defensive patterns
Strategy: validation
Validate before calling
static readonly HashSet<string> ValidNames = new() { "Standalone","Server","iOS","Android","PS4","PS5","XboxOne","GameCoreScarlett","GameCoreXboxOne","EmbeddedLinux","QNX","Kepler","WebGL","tvOS" };
if (!ValidNames.Contains(targetName))
throw new ArgumentException($"'{targetName}' is not a known NamedBuildTarget name."); Type guard
static bool IsValidNamedBuildTargetName(string name) => ValidNames.Contains(name);
Prevention
- Prefer the static NamedBuildTarget singletons over constructing from strings.
- Validate dynamic target-name input against the canonical name set before construction.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- There is no a valid NamedBuildTarget for BuildTargetGroup '{
- Build profile is invalid.
- The 'locationPathName' parameter for BuildPipeline.BuildPlay
- For the '{0}' target the 'locationPathName' parameter for Bu
- '{standaloneSubtarget}' is not a valid subtarget for the Sta
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/37cd99ee35600066.
Report an issue: GitHub.