Take the 2-minute tour ×


How do you figure out which DLL is failing to load (and potentially why) when a process exits with error code -1073741502?


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)


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?

share|improve this question
-1073741502 = 0xC0000142 = 'DLL Initialization failed'. I'm guessing wrong bitness on native dlls (32 vs 64 bit). IIS executes as 64bit unless otherwise configured. –  Simon Svensson Mar 20 '11 at 5:58
That's what I thought too, but the App Pool that it's executing in is configured to "Enable 32-bit Applications." A broader problem is that I just don't know how to debug applications at that level (ie, how to figure out which DLL is failing to load and why it's failing to load). Seems like you'd have to use the Windows SDK to do that, but that's a bit beyond my expertise. –  Ryan Mar 20 '11 at 23:51
You can start with this code, then customize it: stackoverflow.com/q/4139040/19756 –  alexandrul Mar 24 '11 at 11:51
i think you could check the event viewer to identify which dll is not loading –  BigPete Apr 12 '11 at 14:57
don't know if it's relevant, I'm launching cmd /c with java's Runtime.exec() with the same command line and the same parameters, the first 11 times (more or less) it works, from the 12th time onward get the error code -1073741502 –  mic.sca Jul 18 '12 at 12:51

1 Answer 1

up vote 1 down vote accepted

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.



share|improve this answer

Your Answer


