Windows SDK - C# - Debugging process exiting with error code -1073741502

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

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 doing runas /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?

回答1:

I think it can be something related to how windows handles the new processes you are spawning.
Each process will consume non-interactive desktop memory, until you run out of windows heap, and no more processes can be started.

http://www.tomshardware.co.uk/forum/217729-36-application-failed-initialize-properly-0xc0000142

http://blogs.msdn.com/b/ntdebugging/archive/2007/01/04/desktop-heap-overview.aspx



回答2:

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.



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