{"record":{"id":"69093e66731880ec","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"the-file-does-not-contain-an-uninstall-list-expec","errorCode":null,"errorMessage":"The file does not contain an uninstall list. Expected root element 'UninstallList' but found '{reader.LocalName}'.","messagePattern":"The file does not contain an uninstall list\\. Expected root element 'UninstallList' but found '(.+?)'\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"source/UninstallTools/Lists/UninstallList.cs","lineNumber":162,"sourceCode":"                serializer.Serialize(writer, this);\r\n            }\r\n        }\r\n\r\n        internal void Remove(Filter item)\n        {\n            if (Filters.Contains(item))\n                Filters.Remove(item);\n        }\n\n        private static UninstallList Deserialize(XmlSerializer serializer, XmlReader reader)\n        {\n            using (reader)\n            {\n                reader.MoveToContent();\n                if (reader.NodeType != XmlNodeType.Element ||\n                    !string.Equals(reader.LocalName, nameof(UninstallList), StringComparison.Ordinal))\n                {\n                    throw new InvalidDataException(\n                        $\"The file does not contain an uninstall list. Expected root element '{nameof(UninstallList)}' but found '{reader.LocalName}'.\");\n                }\n\n                var result = serializer.Deserialize(reader) as UninstallList;\n                if (result == null)\n                    throw new InvalidDataException(\"The uninstall list file could not be deserialized.\");\n\n                result.Filters ??= new List<Filter>();\n                return result;\n            }\n        }\n\n        private static InvalidDataException CreateInvalidDataException(Exception ex)\n        {\n            var xmlException = ex as XmlException ?? ex.InnerException as XmlException;\n            if (xmlException != null)\n            {\n                return new InvalidDataException(","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/UninstallTools/Lists/UninstallList.cs#L144-L180","documentation":"In UninstallList.Deserialize, after MoveToContent the code asserts the current node is an XmlNodeType.Element whose LocalName equals 'UninstallList'. If the root element is anything else, it throws InvalidDataException naming the unexpected element. This guards against the user opening a non-list XML file (e.g. a different app's export or a hand-edited file) before handing the reader to XmlSerializer.","triggerScenarios":"Calling ReadFromFile on an XML file whose root element is not <UninstallList> — e.g. a <configuration>, <ArrayOfApplicationEntry>, or a renamed old-format file. The check fires before serializer.Deserialize so the failure message names the actual element found.","commonSituations":"User picks the wrong file in the open dialog; a future schema version renames the root element and an old build reads new files; the file was saved by a sibling tool that uses a different root.","solutions":["Verify the root element with a quick XmlReader peek before ReadFromFile, or surface the exception message to the user with a 'not a valid uninstall list' prompt.","Keep the root element name stable across versions; if you must change it, ship a migrator that reads the old name and rewrites.","When bundling sample/template lists, ensure they use the <UninstallList> root."],"exampleFix":"// before\nvar list = UninstallList.ReadFromFile(path);\n\n// after\nusing var peek = XmlReader.Create(path);\npeek.MoveToContent();\nif (peek.LocalName != nameof(UninstallList))\n    MessageBox.Show($\"'{path}' is not an uninstall list (root: {peek.LocalName}).\");\nelse\n    var list = UninstallList.ReadFromFile(path);","handlingStrategy":"validation","validationCode":"using var peek = XmlReader.Create(fileName);\npeek.MoveToContent();\nif (peek.NodeType != XmlNodeType.Element || peek.LocalName != nameof(UninstallList))\n    throw new InvalidDataException($\"Not an uninstall list (root: {peek.LocalName}).\");\nvar list = UninstallList.ReadFromFile(fileName);","typeGuard":"null","tryCatchPattern":"try { list = UninstallList.ReadFromFile(path); }\ncatch (InvalidDataException ex) { MessageBox.Show(ex.Message); }","preventionTips":["Keep the <UninstallList> root element name stable across versions.","Ship a migrator if you ever rename the root element.","Validate with an XSD before deserialising to catch wrong-root files early."],"tags":["xml","invalid-data","uninstall-list","deserialisation","schema-validation"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}