peass-ng/PEASS-ng · error · InvalidOperationException
Task definition does not contain a version.
Error message
Task definition does not contain a version.
What it means
The TaskDefinition.Version property getter parses the version attribute from the task XML document. If the <Task> element lacks a version attribute (or parsing fails), the library throws this InvalidOperationException because a version is mandatory in a Task Scheduler XML definition.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs:1773
private readonly XmlDocument doc;
public DefDoc(string xml)
{
doc = new XmlDocument();
doc.LoadXml(xml);
}
public Version Version
{
get
{
try
{
return new Version(doc["Task"].Attributes["version"].Value);
}
catch
{
throw new InvalidOperationException("Task definition does not contain a version.");
}
}
set
{
var task = doc["Task"];
if (task != null) task.Attributes["version"].Value = value.ToString(2);
}
}
public string Xml => doc.OuterXml;
public bool Contains(string tag, string defaultVal = null, bool removeIfFound = false)
{
var nl = doc.GetElementsByTagName(tag);
while (nl.Count > 0)
{
var e = nl[0];
if (e.InnerText != defaultVal || !removeIfFound || e.ParentNode == null)View on GitHub (pinned to 53fb989abc)
Solutions
- Add a version attribute to the root Task element: <Task version="1.4" ...>
- Validate the XML schema (Task Scheduler 2.0 schema) before loading it into a TaskDefinition
- Use NewTask()/TaskService.NewTask(0) to create a well-formed definition instead of parsing arbitrary XML
- Wrap the property access in try-catch and default to a known version (e.g. 1.2)
Example fix
// before
def.XmlText = File.ReadAllText("legacy.xml"); // no version attribute
// after
var xml = File.ReadAllText("legacy.xml");
if (!xml.Contains("version="))
xml = xml.Replace("<Task ", "<Task version=\"1.4\" ");
def.XmlText = xml; Defensive patterns
Strategy: validation
Validate before calling
var doc = new XmlDocument(); doc.LoadXml(xml);
var ver = doc["Task"]?.Attributes["version"]?.Value;
if (string.IsNullOrEmpty(ver)) throw new ArgumentException("Task XML missing version attribute"); Type guard
bool HasVersion(System.Xml.XmlDocument d) => d["Task"]?.Attributes["version"] != null;
Try / catch
try { var v = def.Version; }
catch (InvalidOperationException) { /* treat as default version 1.2 or reject the XML */ } Prevention
- Always include <Task version="1.x"> when authoring task XML
- Schema-validate task XML before loading into a TaskDefinition
When it happens
Trigger: Accessing taskDefinition.Version on a definition whose XML has no version attribute on the root Task element — e.g. hand-crafted or truncated XML loaded via TaskDefinition.XmlText or a TaskDefinition built from foreign XML.
Common situations: Loading task XML from a template/legacy system that omitted the version attribute; manual XML editing removing attributes; constructing definitions from partial XML strings.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- The current version of the native library (1.{osLibMinorVer}
- A maximum of 32 actions is allowed within a single task.
- Attachments array cannot contain more than 8 items.
- Each value of the array must contain a valid file reference.
- Under Windows 8 and later, EmailAction objects are converted
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/bad2621346275fb7.
Report an issue: GitHub.