从.NET应用程序执行cmd.exe可能导致0xE0434352异常的原因是什么?

时间:2018-05-29 13:56:29

标签: .net taskscheduler

我有一个.net(C#)控制台应用程序,当我通过" start"执行时运行。 VS2017中的按钮,以及直接启动.exe文件时的按钮。但是,当通过Windows任务计划程序执行时,我收到一个非特定错误:0xE0434352

我发现错误是执行此方法的结果:

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");
}

这是什么原因?我得到的例外(来自事件查看器)是:

申请错误

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[])

框架错误

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: 

==============编辑================

在运行时,我正在从映射的网络驱动器中检索JSON文件:

IConfiguration jsonConfig = new ConfigurationBuilder()
    .AddJsonFile("X:\configs", optional: false, reloadOnChange: false)
    .Build();

我发现删除它至少解决了一个问题。虽然可能还有其他人

1 个答案:

答案 0 :(得分:-1)

“Windows任务计划程序”

我打赌它将是Start In字段为空或格式错误。将exe的文件夹放在Start In字段中,然后双引号。 “C:/ YesEven /路径/喜欢/该/”