I have a .net (C#) console application that runs when I execute via the "start" button in VS2017, and also when I launch the .exe
file directly. However, when executed via Windows Task Scheduler I get an unspecific error: 0xE0434352
.
I have found that the error is the result of executing this method:
internal static class Lib
{
internal static async Task<String> ExecuteCmd (string txt, string cli = "cmd.exe", string args = "")
{
using ( Process cmd = new Process
{
StartInfo = new ProcessStartInfo()
{
FileName = cli,
Arguments = args,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = false,
UseShellExecute = false,
}
} )
{
cmd.Start();
await cmd.StandardInput.WriteLineAsync(txt);
await cmd.StandardInput.FlushAsync();
cmd.StandardInput.Close();
cmd.WaitForExit();
return await cmd.StandardOutput.ReadToEndAsync();
}
}
}
// Then that method is called from the Main method like so:
public static async Task Main (string[] args)
{
ExecuteCmd($"echo Complete! >> myFile.log");
}
What is the reason for this? The exceptions I get (from the Event Viewer) are:
Application error
Application: myapp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
at myapp.App+<Main>d__0.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at myapp.App.<Main>(System.String[])
Framework Error
Faulting application name: myapp.exe, version: 1.0.0.0, time stamp: 0x5b0d3a3e
Faulting module name: KERNELBASE.dll, version: 10.0.16299.402, time stamp: 0x81d25214
Exception code: 0xe0434352
Fault offset: 0x00103f12
Faulting process id: 0x51d4
Faulting application start time: 0x01d3f752fb93dfdb
Faulting application path: path\to\myapp.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: c15aa1dc-fb36-49df-a37c-5866116c39d7
Faulting package full name:
Faulting package-relative application ID:
============== EDIT ================
During runtime I am retrieving a JSON file from a mapped network drive:
IConfiguration jsonConfig = new ConfigurationBuilder()
.AddJsonFile("X:\configs", optional: false, reloadOnChange: false)
.Build();
I have found that removing this solves at least one problem. although there may be others
"Windows Task Scheduler"
I bet it'll be the Start In field being empty or malformed. Put the exe's folder in the Start In field, and double quote it. "C:/YesEven/Paths/Like/This/"
User contributions licensed under CC BY-SA 3.0