Iron Python System.typeloadexception: Could Not Load Type 'system.runtime.compilerservices.closure' From Assembly 'system.core'
I am now working with Iron Python to run python based dll in C#. So I have this line in my C# Code: public void Runpython(string name, string id) { var engine = Python.CreateEng
Solution 1:
you can do the same work whitout IronPython
install your libraries in "C:\Program Files\Python39\python.exe" or any python environment
and try this:
publicstringRun(string scriptFilePatch, string args)
{
var psi = new ProcessStartInfo();
psi.FileName = @"C:\Program Files\Python39\python.exe"; // or any python environment
psi.Arguments = $"\"{scriptFilePatch}\" {args}";
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.StandardOutputEncoding = Encoding.UTF8;
string errors = "", result = "";
using (var process = Process.Start(psi))
{
result = process.StandardOutput.ReadToEnd();
errors = process.StandardError.ReadToEnd();
}
StringWriter writer = new StringWriter();
HttpUtility.HtmlDecode(result, writer);
string decodedString = writer.ToString();
return decodedString;
}
Usage:
Run("c:/code/download.py", "\"imageUrl\"\"fileName}"");
and read the arguments in python whit this
Python Code :
import sys
url = sys.argv[1] #arg {imageUrl} recived from c# code
fileName = sys.argv[2] #arg {fileName} recived from c# code
and for return data to c# code you should use this :
b = any_object;
sys.stdout.buffer.write(bytearray(b,"utf-8"))
Post a Comment for "Iron Python System.typeloadexception: Could Not Load Type 'system.runtime.compilerservices.closure' From Assembly 'system.core'"