我正在关注this。 使用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'.
根据this forum中的建议, 我必须承认我没有Microsoft.Scripting.Debugging.dll,因为我不知道它可以在哪里下载 - 它没有配备IronPython。 你能告诉我在哪里可以得到它吗?这是为什么我仍然坚持这个基本的例子?
答案 0 :(得分:0)
ScriptScope scope = engine.CreateScope();
应
dynamic scope = engine.CreateScope();
ScriptScope
是基类。