BCUninstaller/Bulk-Crap-Uninstaller · error · InvalidDataException

The file does not contain an uninstall list. Expected root e

Error message

The file does not contain an uninstall list. Expected root element 'UninstallList' but found '{reader.LocalName}'.

What it means

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.

Source

Thrown at source/UninstallTools/Lists/UninstallList.cs:162

                serializer.Serialize(writer, this);
            }
        }

        internal void Remove(Filter item)
        {
            if (Filters.Contains(item))
                Filters.Remove(item);
        }

        private static UninstallList Deserialize(XmlSerializer serializer, XmlReader reader)
        {
            using (reader)
            {
                reader.MoveToContent();
                if (reader.NodeType != XmlNodeType.Element ||
                    !string.Equals(reader.LocalName, nameof(UninstallList), StringComparison.Ordinal))
                {
                    throw new InvalidDataException(
                        $"The file does not contain an uninstall list. Expected root element '{nameof(UninstallList)}' but found '{reader.LocalName}'.");
                }

                var result = serializer.Deserialize(reader) as UninstallList;
                if (result == null)
                    throw new InvalidDataException("The uninstall list file could not be deserialized.");

                result.Filters ??= new List<Filter>();
                return result;
            }
        }

        private static InvalidDataException CreateInvalidDataException(Exception ex)
        {
            var xmlException = ex as XmlException ?? ex.InnerException as XmlException;
            if (xmlException != null)
            {
                return new InvalidDataException(

View on GitHub (pinned to 608321de98)

Solutions

  1. 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.
  2. Keep the root element name stable across versions; if you must change it, ship a migrator that reads the old name and rewrites.
  3. When bundling sample/template lists, ensure they use the <UninstallList> root.

Example fix

// before
var list = UninstallList.ReadFromFile(path);

// after
using var peek = XmlReader.Create(path);
peek.MoveToContent();
if (peek.LocalName != nameof(UninstallList))
    MessageBox.Show($"'{path}' is not an uninstall list (root: {peek.LocalName}).");
else
    var list = UninstallList.ReadFromFile(path);
Defensive patterns

Strategy: validation

Validate before calling

using var peek = XmlReader.Create(fileName);
peek.MoveToContent();
if (peek.NodeType != XmlNodeType.Element || peek.LocalName != nameof(UninstallList))
    throw new InvalidDataException($"Not an uninstall list (root: {peek.LocalName}).");
var list = UninstallList.ReadFromFile(fileName);

Type guard

null

Try / catch

try { list = UninstallList.ReadFromFile(path); }
catch (InvalidDataException ex) { MessageBox.Show(ex.Message); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BCUninstaller/Bulk-Crap-Uninstaller@608321de98 (2026-08-13). Data as JSON: /api/errors/69093e66731880ec. Report an issue: GitHub.