winsw/winsw · error · InvalidDataException
Start mode in XML must be one of the following:
Error message
Start mode in XML must be one of the following:
What it means
The <startmode> value is parsed into the ServiceStartMode enum via the case-insensitive Enum.Parse. An ArgumentException (value not matching any enum name) is caught and rethrown as InvalidDataException whose message lists the valid enum names. So the set of accepted values is whatever ServiceStartMode defines (typically Boot, System, Automatic, Manual, Disabled).
Source
Thrown at src/WinSW.Core/Configuration/XmlServiceConfig.cs:416
if (p is null)
{
return base.StartMode;
}
try
{
return (ServiceStartMode)Enum.Parse(typeof(ServiceStartMode), p, true);
}
catch (ArgumentException e)
{
var builder = new StringBuilder();
builder.AppendLine("Start mode in XML must be one of the following:");
foreach (string sm in Enum.GetNames(typeof(ServiceStartMode)))
{
builder.AppendLine(sm);
}
throw new InvalidDataException(builder.ToString(), e);
}
}
}
/// <summary>
/// True if the service should be installed with the DelayedAutoStart flag.
/// This setting will be applyed only during the install command and only when the Automatic start mode is configured.
/// </summary>
public override bool DelayedAutoStart => this.SingleBoolElementOrDefault("delayedAutoStart", base.DelayedAutoStart);
public override bool Preshutdown => this.SingleBoolElementOrDefault("preshutdown", base.Preshutdown);
public TimeSpan? PreshutdownTimeout
{
get
{
string? value = this.SingleElementOrNull("preshutdownTimeout");
return value is null ? default : ParseTimeSpan(value);View on GitHub (pinned to 1d0ee4a91b)
Solutions
- Read the valid names from the exception message and use one of them.
- Common valid values: Automatic, Manual, Disabled (and System/Boot).
- For delayed auto-start use <delayedAutoStart> together with Automatic, not a separate start mode.
Example fix
<!-- before --> <startmode>Auto</startmode> <!-- after --> <startmode>Automatic</startmode>
Defensive patterns
Strategy: validation
Validate before calling
var v = dom.DocumentElement!.SelectSingleNode("startmode")?.InnerText;
if (v is not null && !Enum.GetNames(typeof(ServiceStartMode)).Any(n => string.Equals(n, v, StringComparison.OrdinalIgnoreCase)))
throw new InvalidOperationException($"Invalid startmode: {v}"); Try / catch
try { _ = config.StartMode; }
catch (InvalidDataException ex) { /* message lists valid start modes */ } Prevention
- The exception message lists valid names — read it.
- Use Automatic/Manual/Disabled as typical values.
- Pair delayed start with Automatic via <delayedAutoStart>.
When it happens
Trigger: <startmode>something</startmode> where "something" matches no ServiceStartMode name. Case does not matter, but the spelling must equal an enum name.
Common situations: Used "Auto" instead of "Automatic"; used a description like "Delayed"; typo; expected a value the enum doesn't define.
Related errors
- <service> is missing in configuration XML
- 'action' is missing
- Invalid failure action: {action}
- <{tagName}> is missing in configuration XML
- Time Based rolling policy is specified but no pattern can be
AI-assisted analysis of winsw/winsw@1d0ee4a91b (2026-08-13).
Data as JSON: /api/errors/7aed4a929a22fc63.
Report an issue: GitHub.