我得到“ 32位进程无法访问64位进程的模块”。异常调用Process.Start() [英] I get 'A 32 bit processes cannot access modules of a 64 bit process.' exception invoking Process.Start()
问题描述
这是代码示例
var startInfo = new ProcessStartInfo
{
Arguments = commandStr,
FileName = @"C:\Windows\SysWOW64\logman.exe",
};
using (var createCounterProc = new Process { StartInfo = startInfo })
{
createCounterProc.Start();
createCounterProc.WaitForExit();
}
运行代码后,我得到 32位进程无法访问64位进程的模块。 MainModule中的错误消息(NativeErrorCode:299)。我的解决方案配置为AnyCPU。我已经尝试过64位和32位版本的logman.exe(C:\Windows\SysWOW64\logman.exe和C:\Windows\System32\logman.exe),但是我仍然遇到相同的错误。我的操作系统是Win8.1Prox64。可能引起问题的原因?
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?
堆栈跟踪:
at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId)
at System.Diagnostics.Process.get_MainModule()
这是构建配置:
推荐答案
选择用于平台目标的任何CPU 是不够的,您还必须取消选中首选32位,否则该应用程序仍将以32位运行
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.
这篇关于我得到“ 32位进程无法访问64位进程的模块”。异常调用Process.Start()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!