我正在关注这个。一个使用 MonoDev 从 C# 调用 IronPython 的简单示例:
Python:
class Hello:
def __init__(self):
pass
def add(self, x, y):
return (x+y)
C#:
using System;
using IronPython.Hosting;
using IronPython.Runtime;
using IronPython;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting;
class Hello {
public static void Main()
{
ScriptEngine engine = Python.CreateEngine();
ScriptSource script = engine.CreateScriptFromSourceFile("myPythonScript.py");
ScriptScope scope = engine.CreateScope();
script.Execute(scope);
}
}
我在执行相同示例的程序集时遇到了几个问题。而现在我的问题是,每次程序尝试做:
ScriptEngine engine = Python.CreateEngine();
时,我都会收到以下错误:
System.Reflection.TargetInvocationException:
Failed to load language 'IronPython 2.7.3':
An exception was thrown by the type initializer for
IronPython.Runtime.ExtensionMethodSet ---> System.Exception:
An exception was thrown by the type initializer for
IronPython.Runtime.ExtensionMethodSet ---> System.Exception:
Could not load type 'IronPython.Runtime.ExtensionMethodSet+AssemblyLoadInfo[]'
from assembly 'IronPython, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1'.
根据这个论坛中的建议,我不得不承认我没有 Microsoft.Scripting.Debugging.dll,因为我不知道在哪里可以下载它——它没有配备 IronPython。你能告诉我在哪里可以得到它,如果这就是我仍然坚持这个基本示例的原因吗?