Windows SDK - C# - 调试进程退出并出现错误代码 -1073741502
简短版本
当进程退出并出现错误代码 -1073741502 时,如何确定哪个 DLL 无法加载(以及可能的原因)?
长版本
我正在尝试为 Mercurial 编写一个 pretxnchangegroup 挂钩,作为该挂钩的一部分,我需要获取运行命令的输出:
hg log
代码我用来启动和运行 hg.exe 进程的方法如下:
string Command = "log";
Process p = new Process();
ProcessStartInfo psi = p.StartInfo;
p.StartInfo.FileName = @"C:\Program Files (x86)\Mercurial\hg.exe";
psi.CreateNoWindow = true;
psi.LoadUserProfile = true;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.WorkingDirectory = Environment.CurrentDirectory;
p.StartInfo.Arguments = Command;
// Pass-through environment variables
psi.UserName = Properties.Settings.Default.HG_User;
psi.Domain = Properties.Settings.Default.HG_Domain;
psi.Password = new System.Security.SecureString();
foreach (char c in Properties.Settings.Default.HG_Pass)
{
psi.Password.AppendChar(c);
}
p.Start();
p.WaitForExit();
问题是该进程不断退出,错误代码为 -1073741502,并且在标准输出或标准错误上不输出任何内容。经过一些在线研究,我发现这个错误代码与应用程序未能正确初始化有关(也许找不到 DLL?),但我不知道如何解决它。
请记住,当我通过网络推送到存储库时,会调用此挂钩(因此,IIS 通过 Python 调用 Mercurial CGI,该程序已配置为挂钩)。
在一个完全不同的网络应用程序中,我可以很好地运行 HG 命令,而且我也可以通过执行以下操作来运行它 runas /user:<与代码中的帐户相同> /noprofile cmd.exe
,然后在 hg 命令行中手动输入。
另外,如果我设置 UseShellExecute = true
,那么它执行得很好,但我无法获得标准输出。我真的很想对网络应用程序进行网络服务调用,该应用程序能够成功执行此命令,但这将是一个非常丑陋的解决方案。
有什么想法为什么这件事没有执行吗?
SHORT VERSION
How do you figure out which DLL is failing to load (and potentially why) when a process exits with error code -1073741502?
LONG VERSION
I'm trying to write a pretxnchangegroup hook for Mercurial, and as a part of that hook I need to get the output of running the command:
hg log
The code that I'm using to start and run the hg.exe process is as follows:
string Command = "log";
Process p = new Process();
ProcessStartInfo psi = p.StartInfo;
p.StartInfo.FileName = @"C:\Program Files (x86)\Mercurial\hg.exe";
psi.CreateNoWindow = true;
psi.LoadUserProfile = true;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.WorkingDirectory = Environment.CurrentDirectory;
p.StartInfo.Arguments = Command;
// Pass-through environment variables
psi.UserName = Properties.Settings.Default.HG_User;
psi.Domain = Properties.Settings.Default.HG_Domain;
psi.Password = new System.Security.SecureString();
foreach (char c in Properties.Settings.Default.HG_Pass)
{
psi.Password.AppendChar(c);
}
p.Start();
p.WaitForExit();
The problem is that the process keeps exiting with error code -1073741502, without outputting anything on Standard Output or Standard Error. After some research online, I discovered that this error code has something to do with the application failing to initialize properly (couldn't find DLL's, maybe?), but I have no idea how to go about figuring out how to fix it.
Keep in mind that this hook is being called for when I'm pushing to the repository over the web (so, IIS is calling the Mercurial CGI via Python, which has this program configured as a hook).
In a totally different web application, I'm able to run HG commands just fine, and I'm also able to run this by doingrunas /user:<same account as in the code> /noprofile cmd.exe
and then manually typing in the hg command line.
Also, if I set UseShellExecute = true
, then it executes just fine, but then I can't get the Standard Output. I'm really tempted to just make a web service call to the web app which is able to execute this command successfully, but that'd be a really ugly solution.
Any ideas why this thing isn't executing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过禁用 UAC 来解决这个问题,因此这听起来像是一个权限问题,尽管我不知道确切的细节。
I was able to resolve this by disabling UAC so it sounds like a permissions problem even though I do not know the exact details.