Last week I posted this question: How can I get the console application output when I run it as a process in the C # dll as I was trying to find out the cause of the problem I was experiencing. However, I could not find the reason why I received the error message, so I thought that I would ask to track that this was related to the problem that I encountered.
I am working on a method in a DLL and I need to run a process in it. The code used for this:
ProcessStartInfo psi = new ProcessStartInfo(); psi.UseShellExecute = false; psi.ErrorDialog = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.RedirectStandardInput = true; psi.CreateNoWindow = true; psi.FileName = @"C:\Program Files\OpenMS-1.6\XTandemAdapter.exe"; psi.Arguments = @"-ini C:\XTandemAdapter.ini"; Process getIDs = new Process(); getIDs.StartInfo = psi; getIDs.Start(); StreamWriter inputWriter = getIDs.StandardInput; StreamReader outputReader = getIDs.StandardOutput; StreamReader errorReader = getIDs.StandardError; getIDs.WaitForExit(); System.Diagnostics.EventLog.WriteEntry("FMANWiff", "ID output: " + outputReader.ReadToEnd()); System.Diagnostics.EventLog.WriteEntry("FMANWiff", "ID error: " + errorReader.ReadToEnd());
The XTandemAdapter.exe application usually runs as a console application, and FileName and Arguments are designed to play this format: XtandemAdapter.exe -ini XTandemAdapter.ini
I have a console test application that calls my method in this DLL. When I use this, I can see the results of the standoutput redirection, and I see that the process is successful (the executable that is being called also outputs the XML file as output, and I see that it was created). However, in normal operation, the application calls the method in the DLL, which in turn ends with a call to mine. When I run it this way, I see that the process was created when viewed in the task manager, but it quickly ends, and there is no way out in the event log, and the executable is not created by the output file.
Does anyone know why it will work correctly in one case, but not in another? Something done differently when called through a console application or called by a method in dll?
EDIT: I noticed that the Exitcode returned by the process is Exitcode: -529697949, so I think something is going wrong in the process. I will review the code for the xtandemadapter and try to figure out where this comes from. When I launch it from the console application, it returns 0.
EDIT: When I added the debugger debugging operator, I finished work on this method and looked at the value of the process objects, both when using the console test application and in the real world. I found the differences, but I'm not sure what to do with them.
Application for testing the working console:
- getIDs {System.Diagnostics.Process (XTandemAdapter)} System.Diagnostics.Process + base {System.Diagnostics.Process (XTandemAdapter)} System.ComponentModel.Component {System.Diagnostics.Process} BasePriority 8 int EnableRaisingEvents false bool ExitCode 9 int + ExitTime {10/4/2011 1:21:33 AM} System.DateTime + Handle 1036 System.IntPtr HandleCount 53 int HasExited true bool Id 2732 int MachineName "." string + MainModule 'getIDs.MainModule' threw an exception of type 'System.ComponentModel.Win32Exception' System.Diagnostics.ProcessModule {System.ComponentModel.Win32Exception} + MainWindowHandle 0 System.IntPtr MainWindowTitle "" string + MaxWorkingSet 'getIDs.MaxWorkingSet' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException} + MinWorkingSet 'getIDs.MinWorkingSet' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException} + Modules 'getIDs.Modules' threw an exception of type 'System.ComponentModel.Win32Exception' System.Diagnostics.ProcessModuleCollection {System.ComponentModel.Win32Exception} NonpagedSystemMemorySize 3240 int NonpagedSystemMemorySize64 3240 long PagedMemorySize 3010560 int PagedMemorySize64 3010560 long PagedSystemMemorySize 120196 int PagedSystemMemorySize64 120196 long PeakPagedMemorySize 3010560 int PeakPagedMemorySize64 3010560 long PeakVirtualMemorySize 137424896 int PeakVirtualMemorySize64 137424896 long PeakWorkingSet 9064448 int PeakWorkingSet64 9064448 long + PriorityBoostEnabled 'getIDs.PriorityBoostEnabled' threw an exception of type 'System.InvalidOperationException' bool {System.InvalidOperationException} + PriorityClass 'getIDs.PriorityClass' threw an exception of type 'System.InvalidOperationException' System.Diagnostics.ProcessPriorityClass {System.InvalidOperationException} PrivateMemorySize 3010560 int PrivateMemorySize64 3010560 long + PrivilegedProcessorTime {00:00:00.0937500} System.TimeSpan ProcessName "XTandemAdapter" string + ProcessorAffinity 'getIDs.ProcessorAffinity' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException} Responding true bool SessionId 0 int + StandardError {System.IO.StreamReader} System.IO.StreamReader + StandardInput {System.IO.StreamWriter} System.IO.StreamWriter + StandardOutput {System.IO.StreamReader} System.IO.StreamReader + StartInfo {System.Diagnostics.ProcessStartInfo} System.Diagnostics.ProcessStartInfo + StartTime {10/4/2011 1:21:32 AM} System.DateTime SynchronizingObject null System.ComponentModel.ISynchronizeInvoke + Threads {System.Diagnostics.ProcessThreadCollection} System.Diagnostics.ProcessThreadCollection + TotalProcessorTime {00:00:00.8125000} System.TimeSpan + UserProcessorTime {00:00:00.7187500} System.TimeSpan VirtualMemorySize 132001792 int VirtualMemorySize64 132001792 long WorkingSet 9064448 int WorkingSet64 9064448 long + Static members + Non-Public members
When I call the dll, as I expect, and when it does not work:
- getIDs {System.Diagnostics.Process} System.Diagnostics.Process + base {System.Diagnostics.Process} System.ComponentModel.Component {System.Diagnostics.Process} + BasePriority 'getIDs.BasePriority' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} EnableRaisingEvents false bool ExitCode -529697949 int + ExitTime {10/4/2011 1:03:09 AM} System.DateTime + Handle 4176 System.IntPtr + HandleCount 'getIDs.HandleCount' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} HasExited true bool Id 596 int MachineName "." string - MainModule 'getIDs.MainModule' threw an exception of type 'System.ComponentModel.Win32Exception' System.Diagnostics.ProcessModule {System.ComponentModel.Win32Exception} + base {"Access is denied"} System.Runtime.InteropServices.ExternalException {System.ComponentModel.Win32Exception} NativeErrorCode 5 int + Non-Public members - MainWindowHandle 'getIDs.MainWindowHandle' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException} + base {"Process has exited, so the requested information is not available."} System.SystemException {System.InvalidOperationException} + MainWindowTitle 'getIDs.MainWindowTitle' threw an exception of type 'System.InvalidOperationException' string {System.InvalidOperationException} + MaxWorkingSet 'getIDs.MaxWorkingSet' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException} + MinWorkingSet 'getIDs.MinWorkingSet' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException} + Modules 'getIDs.Modules' threw an exception of type 'System.ComponentModel.Win32Exception' System.Diagnostics.ProcessModuleCollection {System.ComponentModel.Win32Exception} + NonpagedSystemMemorySize 'getIDs.NonpagedSystemMemorySize' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + NonpagedSystemMemorySize64 'getIDs.NonpagedSystemMemorySize64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + PagedMemorySize 'getIDs.PagedMemorySize' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + PagedMemorySize64 'getIDs.PagedMemorySize64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + PagedSystemMemorySize 'getIDs.PagedSystemMemorySize' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + PagedSystemMemorySize64 'getIDs.PagedSystemMemorySize64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + PeakPagedMemorySize 'getIDs.PeakPagedMemorySize' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + PeakPagedMemorySize64 'getIDs.PeakPagedMemorySize64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + PeakVirtualMemorySize 'getIDs.PeakVirtualMemorySize' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + PeakVirtualMemorySize64 'getIDs.PeakVirtualMemorySize64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + PeakWorkingSet 'getIDs.PeakWorkingSet' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + PeakWorkingSet64 'getIDs.PeakWorkingSet64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + PriorityBoostEnabled 'getIDs.PriorityBoostEnabled' threw an exception of type 'System.InvalidOperationException' bool {System.InvalidOperationException} + PriorityClass 'getIDs.PriorityClass' threw an exception of type 'System.InvalidOperationException' System.Diagnostics.ProcessPriorityClass {System.InvalidOperationException} + PrivateMemorySize 'getIDs.PrivateMemorySize' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + PrivateMemorySize64 'getIDs.PrivateMemorySize64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + PrivilegedProcessorTime {00:00:00.0468750} System.TimeSpan + ProcessName 'getIDs.ProcessName' threw an exception of type 'System.InvalidOperationException' string {System.InvalidOperationException} + ProcessorAffinity 'getIDs.ProcessorAffinity' threw an exception of type 'System.InvalidOperationException' System.IntPtr {System.InvalidOperationException} + Responding 'getIDs.Responding' threw an exception of type 'System.InvalidOperationException' bool {System.InvalidOperationException} + SessionId 'getIDs.SessionId' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + StandardError {System.IO.StreamReader} System.IO.StreamReader + StandardInput {System.IO.StreamWriter} System.IO.StreamWriter + StandardOutput {System.IO.StreamReader} System.IO.StreamReader + StartInfo {System.Diagnostics.ProcessStartInfo} System.Diagnostics.ProcessStartInfo + StartTime {10/4/2011 1:03:09 AM} System.DateTime SynchronizingObject null System.ComponentModel.ISynchronizeInvoke + Threads 'getIDs.Threads' threw an exception of type 'System.InvalidOperationException' System.Diagnostics.ProcessThreadCollection {System.InvalidOperationException} + TotalProcessorTime {00:00:00.0781250} System.TimeSpan + UserProcessorTime {00:00:00.0312500} System.TimeSpan + VirtualMemorySize 'getIDs.VirtualMemorySize' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + VirtualMemorySize64 'getIDs.VirtualMemorySize64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + WorkingSet 'getIDs.WorkingSet' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException} + WorkingSet64 'getIDs.WorkingSet64' threw an exception of type 'System.InvalidOperationException' long {System.InvalidOperationException} + Static members System.Diagnostics.Process System.Diagnostics.Process + Non-Public members {System.Diagnostics.Process} System.Diagnostics.Process 'getIDs.MainModule' threw an exception of type 'System.ComponentModel.Win32Exception' Too many characters in character literal
Another EDIT: I found myself getting this error in the system event viewer. I have not noticed so far. "Application popup: XTandemAdapter.exe - Application Error: Application failed to initialize correctly (0xe06d7363). Click OK to terminate the application."
Does this help anyone understand the problem. It should be noted that the executable needs to use several dlls, although depending on the host of dependencies, they are all found.