While a C# program is running I am unable to separately run an ANSI C program

Harold Zwier 1 Reputation point
2022-06-01T10:02:34.377+00:00

My problem is that when my C# application is running. I cannot successfully run some .exe programs created from an ANSI C source. The event viewer (Administrative events) shows the following error. No error shows in the C# software:

Faulting application name: ediexprt.exe, version: 0.0.0.0, time stamp: 0x62901b9f
Faulting module name: ucrtbase.dll, version: 10.0.19041.789, time stamp: 0x2bd748bf
Exception code: 0xc0000409
Fault offset: 0x0000000000071208
Faulting process id: 0x4644
Faulting application start time: 0x01d875870d36869d
Faulting application path: f:\EDIhz520\ediexprt.exe
Faulting module path: C:\WINDOWS\System32\ucrtbase.dll
Report Id: 0af44e01-ca73-4455-b429-dbd6b60643ce
Faulting package full name:
Faulting package-relative application ID:

I originally wrote an ANSI C commercial application in the late 1990s and it has been running successfully since then with development as required. Of recent times I have been developing an application in C# and have managed to work through the issues that have arisen as I learned about C#. But I cannot solve the problem described here, nor can I find any references to the problem on the web.

My C# application and the ANSI C application are both being developed on the latest Windows version 10, but I have the same problem on Windows 11. I have been developing the C# application in Visual Studio 2019, but today I compiled it under VS 2022 (on the Windows 11 computer) and have the same problem.

I have no reason to believe that c:\windows\system32\ucrtbase.dll is corrupt. If the C# software is not running, then the ANSI C program runs without problem.

The C# application (EDImenu.exe) is currently 711KB in size and growing as I add to the software. The problem first occurred when “using System.Diagnostics” to use the Process Class to start my ANSI C ediexprt.exe program as an external process. The ANSI C .exe is 147KB in size.

When the C# software tried to start the ANSI C .exe, an error showed in the Event Viewer as described earlier. No error showed in the C# software, but I did get a Process result of -1073740791 and that value appears whenever the external Process fails. The ANSI C program did not start. I tried many different ways to get around the problem including starting up a detached child process. The same error occurred. I then tried simply starting the C# software and then in a separate command shell tried to manually run the ANSI program. As before an error appeared in the Event Viewer.

I have found 2 instances in which my ANSI software can be started from a C# program. In the first instance I simply wrote a small C# program that did nothing other than start the ANSI C software via the Process Class. The ANSI C software ran correctly. The second instance was to write a “Hello World” program in ANSI C and when I started this program from my C# program. It ran successfully. I have been unable to find any workaround to successfully run the ANSI C software I need to run. Can you help me?

Developer technologies C#
{count} votes

3 answers

Sort by: Most helpful
  1. RLWA32 49,536 Reputation points
    2022-06-01T11:30:10.65+00:00

    If the C# software is not running, then the ANSI C program runs without problem.

    While the C# application is running have you tried running your C program under the debugger 1) as a child process of the C# application and 2) as a standalone process?

    Without installing an extension the Visual Studio debugger does not support automatically debugging child processes. However, you could include a call to __debugbreak at startup to give you an opportunity to attach the debugger. You could also use WinDbg which does support debugging child processes.


  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-06-01T20:35:15.18+00:00

    if C program runs fine in the console, then the issue is probably the startup parameters in the process start.

    be sure stdin, stdout, and stderr are set to values the C program will support in ProcessStartInfo


  3. Harold Zwier 1 Reputation point
    2022-06-02T08:22:39.15+00:00

    The problem has now been resolved. The problem was caused by my own software and the comment from @RLWA32 and the answer from @Bruce (SqlWork.com) significantly helped me to get to the cause of the problem.

    Both my C# and ANSI C software opened the same error log file (let's call it errlogger.log). The ANSI C software opened the file by redirecting stdout (output normally sent to the console) to the error log. The C# software simply opened the error log and within my C# software any errors found were written to the error log. Of course if the C# software was running (and therefore had the error log open), then the ANSI C software was unable to redirect stdout to that same error log file.

    Simple really, and I should have picked up on the problem earlier. The suggestion to run my ANSI C software in the VS debugger and the suggestion to see what values were set for stdin, stdout, and stderr both helped me to think about the problem differently. Many thanks.

    After altering my C# software to use a different named error log file, I now have the C# software using the Process class to start the external ANSI C program and it is working without a problem. There are of course a number of ways to solve the problem. I might try a few other ways.

    Many thanks to all.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.