BCUninstaller/Bulk-Crap-Uninstaller · error · InvalidDataException

String contains invalid characters. Data:

Error message

String contains invalid characters. Data: 

What it means

SafeNormalize pre-cleans the string by replacing non-characters with '?' before calling Normalize, but if Normalize still throws ArgumentException the input contains code points the requested NormalizationForm cannot process. The rethrown InvalidDataException embeds the UTF-32 hex dump of the input to aid diagnosis.

Source

Thrown at source/KlocTools/Extensions/StringExtensions.cs:427

            const string pattern = @"(?<=\w)(?=[A-Z])";
            baseStr = Regex.Replace(baseStr.ToPascalCase(), pattern, " ", RegexOptions.None);
            return baseStr.Substring(0, 1).ToUpperInvariant() + baseStr.Substring(1);
        }

        /// <summary>
        /// Safe version of normalize that doesn't crash on invalid code points in string.
        /// Instead the points are replaced with question marks.
        /// </summary>
        public static string SafeNormalize(this string input, NormalizationForm normalizationForm = NormalizationForm.FormC)
        {
            try
            {
                return StringTools.ReplaceNonCharacters(input, '?').Normalize(normalizationForm);
            }
            catch (ArgumentException e)
            {
                throw new InvalidDataException("String contains invalid characters. Data: " + Encoding.UTF32.GetBytes(input).ToHexString(), e);
            }
        }

        #endregion Methods
    }
}

View on GitHub (pinned to 608321de98)

Solutions

  1. Sanitize or strip invalid code points before normalizing.
  2. Catch InvalidDataException and fall back to a lossy cleaning (e.g. replace offenders with '?').
  3. Verify and correct the source encoding before normalization.

Example fix

// before
var n = input.SafeNormalize();
// after
string n;
try { n = input.SafeNormalize(); }
catch (InvalidDataException) { n = StringTools.ReplaceNonCharacters(input, '?').Normalize(); }
Defensive patterns

Strategy: try-catch

Validate before calling

// Strip suspect code points before normalising
input = StringTools.ReplaceNonCharacters(input, '?');

Try / catch

try { return input.SafeNormalize(form); }
catch (InvalidDataException) { return StringTools.ReplaceNonCharacters(input, '?').Normalize(form); }

Prevention

When it happens

Trigger: Input containing lone surrogate fragments, unassigned code points, or combining sequences invalid for the requested form; binary data treated as a string.

Common situations: Reading malformed text from external sources; concatenating strings of mixed encodings; corrupt database fields; importing data with broken surrogates.

Understand the failure class

Related errors


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