.NET 进程抛出 System.InvalidOperationException

问题描述

我已经尝试了我在网上找到的所有解决方案,但都没有奏效。 我确保我已经转义了所有引号并双引号其中有空格的任何路径,我已经确保所有进程正常和正确启动。 但由于某种原因,此进程在内部失败并返回退出代码 100,并抛出此特定错误

具体的工作:

  • 函数/进程在 cmd 和 powershell 中运行良好。
  • Windows 事件日志没有说明任何关于错误的额外信息。和标题说的一样。

我尝试过的事情:

我不知道自己做错了什么,为此浪费了一天。 请有人给出比windows更好的解释...

// USING ESET
processstartinfo psi = new processstartinfo();
//Set pathway
if (System.IO.File.Exists($@"{ConfigurationManager.AppSettings["ESETPath"]}\ecls.exe"))
    psi.FileName = $@"""{ConfigurationManager.AppSettings["ESETPath"]}\ecls.exe""";
else
    psi.FileName = $@"""{ConfigurationManager.AppSettings["ESETAlternativePath"]}\ecls.exe""";
//Set arguments
psi.Arguments = $"--log-file={ConfigurationManager.AppSettings["ESETLogFilePath"]} --no-log-console --log-all {FilePath}";
psi.CreateNowindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;

//Create process with Process Info
Process proc = Process.Start(psi);
proc.WaitForExit(AllowedTimePeriod);

if (proc.HasExited == false)
{
    proc.Kill();
    throw new Exception("Error occured. Anti-Virus Scan Could not complete the operation. Scanning time period too long.");
}

//Log
string stdout = proc.StandardOutput.ReadToEnd();
string stderr = proc.StandardError.ReadToEnd();

switch (proc.ExitCode)
{
    case 0: VirusFound = false; return true;
    case 1:
        VirusFound = true;
        if (System.IO.File.Exists(FilePath))
        {
            System.IO.File.Delete(FilePath);
        }
        return true;
    default:
        throw new Exception("Error occured. Anti-Virus Scan Could not complete the operation. Returned Error Code " + proc.ExitCode.ToString());
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)