BCUninstaller/Bulk-Crap-Uninstaller · warning · InvalidOperationException
Process has no MainModule
Error message
Process has no MainModule
What it means
Thrown by the window-targeting feature when the user drags the crosshair onto a window and the targeted process's MainModule resolves to null. Process.MainModule is null when the caller cannot enumerate the target's modules (typically a bitness mismatch, insufficient privilege, or the process having exited). BCU catches it and shows a generic error dialog.
Source
Thrown at source/BulkCrapUninstaller/Forms/Helpers/TargetWindow.cs:68
DialogResult = DialogResult.OK;
Close();
DirectoriesSelected?.Invoke(this, e);
}
private void WindowTargeter1OnPickingStarted(object sender, EventArgs e)
{
_setMainWindowVisible(false);
}
private void WindowTargeterWindowSelected(object sender, Klocman.Subsystems.WindowHoverEventArgs e)
{
_setMainWindowVisible(true);
try
{
var fileName = e.TargetWindow.GetRunningProcess().MainModule?.FileName;
if (fileName == null)
throw new InvalidOperationException("Process has no MainModule");
var parentDirectory = new FileInfo(fileName).Directory;
if (parentDirectory == null)
throw new InvalidOperationException("Failed to get MainModule Directory");
// Ignore targeting BCU itself
if (PathTools.SubPathIsInsideBasePath(Program.AssemblyLocation.FullName, fileName, true, true))
return;
OnDirectoriesSelected(new DirectoriesSelectedEventArgs(parentDirectory.ToEnumerable().ToList()));
}
catch (Exception exception)
{
Console.WriteLine(exception);
PremadeDialogs.GenericError(exception);
}
}
View on GitHub (pinned to 608321de98)
Solutions
- Run BCU as administrator so it can inspect the target process modules.
- Use the BCU build that matches the OS architecture (x64 BCU on x64 Windows).
- Target a different window whose process is still running and inspectable.
- Browse to the directory manually instead of using the window targeter.
Defensive patterns
Strategy: try-catch
Try / catch
try { var fileName = proc.MainModule?.FileName; /* ... */ }
catch (InvalidOperationException) { /* inform user, skip target */ } Prevention
- Run BCU elevated when targeting arbitrary processes.
- Use the BCU build matching the OS architecture (x64 on x64).
- Avoid targeting system/service processes that resist module enumeration.
When it happens
Trigger: Targeting a 64-bit system process from 32-bit BCU (or vice versa); targeting a process running at higher integrity (e.g. a service); targeting a window whose process exited between hover and selection; targeting a UWP/store app.
Common situations: Running non-elevated BCU against an elevated app; using the x86 BCU build on x64 Windows against svchost/System; targeting store apps.
Related errors
- Could not close running instance of Regedit
- Failed to get MainModule Directory
- Failed to call the API
- Process name can't be null or empty
- regedit.exe failed to execute properly
AI-assisted analysis of BCUninstaller/Bulk-Crap-Uninstaller@608321de98 (2026-08-13).
Data as JSON: /api/errors/aa2517134b4db165.
Report an issue: GitHub.