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

送分小仙女□ 提交于 2020-01-11 04:39:17

问题


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: enter image description here


回答1:


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.




回答2:


After investigation I realized that Logman.exe is unmanaged code, so it cannot return a .NET object as MainModule, so it's a normal behavior. I'ts just slightly confusing error message for Win32Exception. It doesn't influence the execution of Process.Start().



来源:https://stackoverflow.com/questions/34070969/i-get-a-32-bit-processes-cannot-access-modules-of-a-64-bit-process-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!