{"record":{"id":"ec949bf69e84a5a2","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"the-uninstall-list-file-could-not-be-deserialized","errorCode":null,"errorMessage":"The uninstall list file could not be deserialized.","messagePattern":"The uninstall list file could not be deserialized\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"source/UninstallTools/Lists/UninstallList.cs","lineNumber":168,"sourceCode":"            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(\n                    $\"The uninstall list XML is invalid at line {xmlException.LineNumber}, position {xmlException.LinePosition}: {xmlException.Message}\",\n                    ex);\n            }\n\n            return new InvalidDataException(\"The uninstall list file is not valid XML.\", ex);\n        }","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/UninstallTools/Lists/UninstallList.cs#L150-L186","documentation":"In Deserialize, after the root-element check passes, the code runs serializer.Deserialize(reader) as UninstallList and throws InvalidDataException if the result is null. A null result means the XmlSerializer returned null (which happens when the element existed but contained no deserialisable content, or the cast target mismatched), so the caller would otherwise get a NullReferenceException on result.Filters.","triggerScenarios":"The XML has a <UninstallList> root that passed the name check but Deserialize still returned null — e.g. xsi:nil=\"true\" on the root, a serialisation attribute mismatch between the assembly that wrote and the one that reads, or a corrupted element that the serializer silently skips.","commonSituations":"Version skew: the UninstallList class was refactored (renamed/namespace-changed) and an old file's root matches the local name but the type no longer maps; partial/corrupt file that deserialises to nothing.","solutions":["Keep the UninstallList type name/namespace stable, or add an XmlType/XmlRoot alias matching the legacy name.","On this exception, offer to open the file as text so the user can inspect/recover it.","Add an XML schema (XSD) and validate before deserialising to surface corruption earlier."],"exampleFix":"// before\nvar result = serializer.Deserialize(reader) as UninstallList;\n\n// (library code) after — keep type identity stable:\n[XmlRoot(\"UninstallList\"), XmlType(\"UninstallList\")]\npublic class UninstallList { /* ... */ }\n\n// caller side: catch and recover\ntry { list = UninstallList.ReadFromFile(path); }\ncatch (InvalidDataException) { list = RestoreFromBackup(path); }","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { list = UninstallList.ReadFromFile(path); }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"could not be deserialized\"))\n{\n    list = RestoreFromBackup(path) ?? new UninstallList();\n}","preventionTips":["Keep the UninstallList type name and namespace stable between releases; add XmlRoot/XmlType aliases if renaming.","Version-stamp list files and ship forward-migrators.","Round-trip-test serialisation on every schema change."],"tags":["xml","invalid-data","uninstall-list","deserialisation","null-result","version-skew"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}