BCUninstaller/Bulk-Crap-Uninstaller · error · ArgumentException

Value cannot contain newlines

Error message

Value cannot contain newlines

What it means

The same Filter(string name, string filterText) constructor checks filterText.ContainsAny(StringTools.NewLineChars) and throws ArgumentException (param 'filterText') if it contains any newline character. Filters are single-line match expressions; a newline would create an ambiguous multi-line rule and break serialisation round-trips, so it is rejected explicitly after the empty-check.

Source

Thrown at source/UninstallTools/Lists/Filter.cs:30

namespace UninstallTools.Lists
{
    public class Filter : ITestEntry
    {
        public Filter()
        {
        }

        public Filter(string name, string filterText)
        {
            if (!string.IsNullOrEmpty(name))
                Name = name;

            if (string.IsNullOrEmpty(filterText))
                throw new ArgumentException(Localisation.UninstallListItem_ValueEmpty, nameof(filterText));

            if (filterText.ContainsAny(StringTools.NewLineChars, StringComparison.Ordinal))
                throw new ArgumentException(Localisation.UninstallListItem_NewLineInValue, nameof(filterText));

            ComparisonEntries.Add(new FilterCondition { FilterText = filterText });
        }

        public Filter(string name, bool exclude, params FilterCondition[] conditions)
        {
            if (!string.IsNullOrEmpty(name))
                Name = name;
            Exclude = exclude;
            ComparisonEntries.AddRange(conditions);
        }

        public string Name { get; set; } = Localisation.UninstallListEditor_NewFilter;

        /// <summary>
        /// Exclude items matched by this entry from results of the parent uninstall list
        /// </summary>
        public bool Exclude { get; set; }

View on GitHub (pinned to 608321de98)

Solutions

  1. Strip newline characters before constructing the Filter: filterText = filterText.Replace("\r", " ").Replace("\n", " ") (or split into multiple Filter objects).
  2. In the UI, use a single-line TextBox (Multiline=false) for filter input.
  3. Normalise loaded XML text with XmlReaderSettings.IgnoreWhitespace and trim before passing to the constructor.

Example fix

// before
var filter = new Filter(name, rawFilterText);

// after
var cleaned = string.Join(' ', rawFilterText.Split(StringTools.NewLineChars,
    StringSplitOptions.RemoveEmptyEntries));
var filter = new Filter(name, cleaned);
Defensive patterns

Strategy: validation

Validate before calling

var cleaned = string.Join(' ',
    (filterText ?? string.Empty).Split(StringTools.NewLineChars,
        StringSplitOptions.RemoveEmptyEntries));
if (string.IsNullOrWhiteSpace(cleaned))
    throw new InvalidOperationException("Filter text is required.");
var filter = new Filter(name, cleaned);

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Passing filterText that contains '\r', '\n', or '\r\n' to 'new Filter(name, filterText)'. Happens when copying a multi-line selection from a textbox, pasting from a clipboard that includes a trailing newline, or deserialising XML where the element text was written with formatting indentation.

Common situations: User pastes a filter copied from a chat/log that spans two lines; XML serialiser preserves whitespace/newlines in element content; programmatic filter built from Environment.NewLine-joined tokens.

Related errors


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