{"record":{"id":"aa2517134b4db165","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"process-has-no-mainmodule","errorCode":null,"errorMessage":"Process has no MainModule","messagePattern":"Process has no MainModule","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"source/BulkCrapUninstaller/Forms/Helpers/TargetWindow.cs","lineNumber":68,"sourceCode":"            DialogResult = DialogResult.OK;\r\n            Close();\r\n            DirectoriesSelected?.Invoke(this, e);\r\n        }\r\n\r\n        private void WindowTargeter1OnPickingStarted(object sender, EventArgs e)\r\n        {\r\n            _setMainWindowVisible(false);\r\n        }\r\n\r\n        private void WindowTargeterWindowSelected(object sender, Klocman.Subsystems.WindowHoverEventArgs e)\r\n        {\r\n            _setMainWindowVisible(true);\r\n\r\n            try\r\n            {\r\n                var fileName = e.TargetWindow.GetRunningProcess().MainModule?.FileName;\r\n                if (fileName == null)\r\n                    throw new InvalidOperationException(\"Process has no MainModule\");\r\n\r\n                var parentDirectory = new FileInfo(fileName).Directory;\r\n                if (parentDirectory == null)\r\n                    throw new InvalidOperationException(\"Failed to get MainModule Directory\");\r\n\r\n                // Ignore targeting BCU itself\r\n                if (PathTools.SubPathIsInsideBasePath(Program.AssemblyLocation.FullName, fileName, true, true))\r\n                    return;\r\n\r\n                OnDirectoriesSelected(new DirectoriesSelectedEventArgs(parentDirectory.ToEnumerable().ToList()));\r\n            }\r\n            catch (Exception exception)\r\n            {\r\n                Console.WriteLine(exception);\r\n                PremadeDialogs.GenericError(exception);\r\n            }\r\n        }\r\n\r","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/BulkCrapUninstaller/Forms/Helpers/TargetWindow.cs#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running non-elevated BCU against an elevated app; using the x86 BCU build on x64 Windows against svchost/System; targeting store apps.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var fileName = proc.MainModule?.FileName; /* ... */ }\ncatch (InvalidOperationException) { /* inform user, skip target */ }","preventionTips":["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."],"tags":["window-targeting","process","permissions","bitness"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}