Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get 'A 32 bit processes cannot access modules of a 64 bit process.' exception invoking Process.Start()

Here is the code sample

var startInfo = new ProcessStartInfo
{
    Arguments = commandStr,
    FileName = @"C:\Windows\SysWOW64\logman.exe",
};

using (var createCounterProc = new Process { StartInfo = startInfo })
{
    createCounterProc.Start();
    createCounterProc.WaitForExit();
}

After running the code I get "A 32 bit processes cannot access modules of a 64 bit process." message in MainModule (NativeErrorCode:299). My solution is configured to AnyCPU. I've tried both 64 and 32 bit versions of logman.exe (C:\Windows\SysWOW64\logman.exe and C:\Windows\System32\logman.exe) but I still have the same error. My OS is Win8.1Prox64. What could cause the problem?

Stack trace:

at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
   at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId)
   at System.Diagnostics.Process.get_MainModule()

Here is the Build configuration:

build settings dialog

like image 359
Max Avatar asked Dec 03 '15 16:12

Max


1 Answers

Choosing Any CPU for Platform target is not enough, you also have to uncheck Prefer 32-bit, otherwise the application will still be run as a 32-bit application.

This is only possible on application projects, not on library project. If your project is a library, you must do it in the project using your library.

like image 115
Albireo Avatar answered Nov 15 '22 20:11

Albireo