猿问

在 .net c# 控制器中使用 phyton.exe:

无法加载文件或程序集“python.runtime”或其依赖项之一,尝试加载格式正确的程序


我面临同样的问题,我的错误没有使用 phyton 3.5 解决,调用 phyton.exe 路径在 .net c# 控制器中执行 phyton 文件,只有在发布到服务器后才会遇到错误,它在我的系统中工作正常


下面是我的代码


if (Result.Success)

{

    System.Diagnostics.Process process = new System.Diagnostics.Process();

    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

    startInfo.FileName = "C:/Program Files/Python 3.5/python.exe";

    startInfo.Arguments = "C:/PythonScripts/Test.py";

    // startInfo.Arguments = HttpContext.Server.MapPath("~/PythonScripts/Test.py").ToString();


    startInfo.Verb = "runas";

    startInfo.UseShellExecute = false;

    startInfo.RedirectStandardError = true;

    startInfo.RedirectStandardOutput = true;

    process.StartInfo = startInfo;

    bool t = process.Start();


    StreamReader myStreamReader = process.StandardError;

    string error = myStreamReader.ReadToEnd();


    StreamReader reader = process.StandardOutput;

    string output = reader.ReadToEnd();


    process.WaitForExit();

    process.Close();


    if (!error.Equals(""))

    {

        Result.Success = false;

        Result.Exception = true;

    }

}

拉丁的传说
浏览 222回答 1
1回答

吃鸡游戏

没有太多关于您正在使用的信息,但有时,这badformatexception是因为您的项目配置与它抱怨的 dll 不兼容,请将其更改为 x86 或 x64。
随时随地看视频慕课网APP
我要回答