BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException

File name cannot be empty.

Error message

File name cannot be empty.

What it means

UninstallList.ReadFromFile(string fileName) guards its entry point with string.IsNullOrWhiteSpace(fileName) and throws ArgumentException (param 'fileName') if the supplied path is blank. ReadFromFile opens the file with File.OpenRead, which would otherwise throw an unhelpful ArgumentNullException/ArgumentException from the framework; the explicit check gives a clear, localised contract.

Source

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

                if (uninstallListItem.TestEntry(input) == true)
                {
                    included = true;
                    break;
                }
                included = false;
            }

            if (!included.HasValue)
                return excluded.HasValue ? true : null;
            return included.Value;
        }

        public bool Enabled { get; set; } = true;

        public static UninstallList ReadFromFile(string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName))
                throw new ArgumentException("File name cannot be empty.", nameof(fileName));

            var serializer = new XmlSerializer(typeof (UninstallList));
            using (var stream = File.OpenRead(fileName))
            {
                if (stream.Length == 0)
                    throw new InvalidDataException("The uninstall list file is empty.");

                try
                {
                    return Deserialize(serializer, XmlReader.Create(stream, ReaderSettings));
                }
                catch (Exception ex) when (ex is InvalidOperationException or XmlException)
                {
                    if (!stream.CanSeek)
                        throw CreateInvalidDataException(ex);

                    stream.Position = 0;
                    using var textReader = new StreamReader(stream, Encoding.UTF8, true, 1024, true);

View on GitHub (pinned to 608321de98)

Solutions

  1. Null/whitespace-check fileName before calling ReadFromFile and bail out (e.g. treat user-cancel as a no-op).
  2. Bind the Open button's Enabled state to whether a non-blank path is selected.
  3. Log the source of the empty path (config key, MRU index) to find the upstream producer.

Example fix

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

// after
if (string.IsNullOrWhiteSpace(pathFromDialog))
    return; // user cancelled or misconfigured
var list = UninstallList.ReadFromFile(pathFromDialog);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(fileName))
    throw new InvalidOperationException("No file path supplied (user cancelled or misconfigured).");
var list = UninstallList.ReadFromFile(fileName);

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Calling UninstallList.ReadFromFile(null), ReadFromFile(""), or ReadFromFile(" "). Common when the filename comes from a config field, command-line arg, or drag-drop handler that yielded nothing.

Common situations: Open-file dialog returns null because the user cancelled and the return value is passed straight through; an MRU list entry with an empty path; a unit test passes null by mistake.

Related errors


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