-4

could not load file or assembly 'python.runtime' or one of its dependencies ,an attempt was made to load a program with an in correct format

im am facing same problem, My error was not resolved using phyton 3.5 , calling the phyton.exe path to execute phyton file in .net c# controller ,facing error only after publishing in to the server ,it working fine in my system

below was my code

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

enter image description here

JP Hellemons
  • 5,977
  • 11
  • 63
  • 128

1 Answers1

0

Not so much info about what you are using, but sometimes, the badformatexception is caused because your project configuration is not compatible with the dll it's complaining about, change it to x86 or to x64.

Nekeniehl
  • 1,633
  • 18
  • 35