{"record":{"id":"97147592040d5fd5","repo":"dotnet/runtime","slug":"both-count-and-length-property-found-on-variable","errorCode":null,"errorMessage":"both count and length property found on: {variable}in template: {templateName}","messagePattern":"both count and length property found on: (.+?)in template: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/coreclr/scripts/genEventing.py","lineNumber":367,"sourceCode":"            nodeMap = dataNode.attributes\n            for attrib in nodeMap.values():\n                attrib_name = attrib.name\n                if attrib_name not in ignoredXmlTemplateAttribes and attrib_name not in usedXmlTemplateAttribes:\n                    raise ValueError('unknown attribute: '+ attrib_name + ' in template:'+ templateName)\n\n        for dataNode in dataNodes:\n            variable = dataNode.getAttribute('name')\n            wintype = dataNode.getAttribute('inType')\n\n            #count and length are the same\n            wincount  = dataNode.getAttribute('count')\n            winlength = dataNode.getAttribute('length');\n\n            var_Props = None\n            var_dependency = [variable]\n            if  winlength:\n                if wincount:\n                    raise Exception(\"both count and length property found on: \" + variable + \"in template: \" + templateName)\n                wincount = winlength\n\n            if (wincount.isdigit() and int(wincount) ==1):\n                wincount = ''\n\n            if  wincount:\n                if (wincount.isdigit()):\n                    var_Props = wincount\n                elif  fnPrototypes.getParam(wincount):\n                    var_Props = wincount\n                    var_dependency.insert(0, wincount)\n                    arrays[variable] = wincount\n\n            #construct the function signature\n\n            if  wintype == \"win:GUID\":\n                var_Props = \"sizeof(GUID)/sizeof(int)\"\n","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/coreclr/scripts/genEventing.py#L349-L385","documentation":"Raised by parseTemplateNodes() in genEventing.py when a <data> element in a template has both a 'count' attribute and a 'length' attribute set simultaneously. In ETW manifests, count and length are semantically equivalent ways to express array sizing, and specifying both is ambiguous and invalid.","triggerScenarios":"Triggered when dataNode.getAttribute('length') returns a non-empty string AND dataNode.getAttribute('count') also returns a non-empty string for the same <data> element. The code checks winlength first; if it's truthy, it then checks wincount, and if both are set, raises immediately.","commonSituations":"A developer editing the manifest adds a length attribute to a data element that already has a count attribute, or vice versa. A merge conflict resolution accidentally leaves both attributes. Copy-paste from another data element brings an extra attribute.","solutions":["Inspect the <data> element identified by the variable name and template tid in the error message.","Remove either the 'count' or 'length' attribute so only one remains.","Decide which is correct: 'count' indicates array element count, 'length' indicates byte length — use the appropriate one for the data semantics."],"exampleFix":"<!-- before: both count and length specified -->\n<data name=\"Values\" inType=\"win:Int32\" count=\"NumValues\" length=\"4\" />\n\n<!-- after: use only count -->\n<data name=\"Values\" inType=\"win:Int32\" count=\"NumValues\" />","handlingStrategy":"validation","validationCode":"import xml.dom.minidom as DOM\n\ndef validate_no_count_length_conflict(manifest_path: str) -> list:\n    \"\"\"Check for <data> elements with both count and length attributes.\"\"\"\n    tree = DOM.parse(manifest_path)\n    conflicts = []\n    for template in tree.getElementsByTagName('template'):\n        tid = template.getAttribute('tid')\n        for data in template.getElementsByTagName('data'):\n            has_count = bool(data.getAttribute('count'))\n            has_length = bool(data.getAttribute('length'))\n            if has_count and has_length:\n                name = data.getAttribute('name')\n                conflicts.append(f\"Template '{tid}', data '{name}' has both count and length\")\n    return conflicts","typeGuard":"null","tryCatchPattern":"try:\n    allTemplates = parseTemplateNodes(templateNodes)\nexcept Exception as e:\n    if 'both count and length' in str(e):\n        print(f\"Manifest error: {e}\")\n        print(\"Remove either 'count' or 'length' from the <data> element — they are mutually exclusive.\")\n    raise","preventionTips":["Never specify both count and length on the same <data> element — they are semantically equivalent.","Add an XML schema or linting check for this constraint.","Review manifest diffs specifically for attribute conflicts.","Document that count = element count and length = byte length, pick one per element."],"tags":["etw","manifest","eventing","coreclr","validation"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}