6

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?

Ryan
  • 2,948
  • 3
  • 30
  • 41
  • 1
    -1073741502 = 0xC0000142 = 'DLL Initialization failed'. I'm guessing wrong bitness on native dlls (32 vs 64 bit). IIS executes as 64bit unless otherwise configured. – sisve Mar 20 '11 at 05: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: http://stackoverflow.com/q/4139040/19756 – alexandrul Mar 24 '11 at 11:51
  • 1
    i think you could check the event viewer to identify which dll is not loading – BigPete Apr 12 '11 at 14:57
  • 1
    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
    any final solution with full source code sample working about it ? – Kiquenet Jul 08 '13 at 09:37

1 Answers1

1

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.

serializer
  • 1,003
  • 2
  • 13
  • 27