使用mono从C#调用IronPython对象
我有以下IronPython代码使用mono从C#调用IronPython对象,c#,mono,ironpython,C#,Mono,Ironpython,我有以下IronPython代码 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
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);
}
}
复制IronPython.dll后,我运行以下命令。(我试着跑gacutil,但我得到了一些
dmcs/r:IronPython.dll callipy.cs
但我得到一些错误信息如下
Could not load file or assembly 'Microsoft.Scripting.ExtensionAttribute, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
Missing method .ctor in assembly /Users/smcho/Desktop/cs/namespace/IronPython.dll, type System.Runtime.CompilerServices.ExtensionAttribute
Can't find custom attr constructor image: /Users/smcho/Desktop/cs/namespace/IronPython.dll mtoken: 0x0a000080
Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
...
无法加载文件或程序集“Microsoft.Scripting.ExtensionAttribute,版本=2.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。
assembly/Users/smcho/Desktop/cs/namespace/IronPython.dll中缺少方法.ctor,类型为System.Runtime.CompilerServices.ExtensionAttribute
找不到自定义属性构造函数映像:/Users/smcho/Desktop/cs/namespace/IronPython.dll mtoken:0x0a000080
无法加载文件或程序集“Microsoft.Scripting.Core,版本=1.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。
无法加载文件或程序集“Microsoft.Scripting.Core,版本=1.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。
无法加载文件或程序集“Microsoft.Scripting.Core,版本=1.0.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。
...
看起来IronPython需要Microsoft.sciting.Core,但对于mono,我不知道该怎么办
- C#可以在Mono上运行IronPython对象吗?如果可以,怎么做
System.Core
。有关详细信息,请参阅
Could not load file or assembly 'Microsoft.Scripting.ExtensionAttribute, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
Missing method .ctor in assembly /Users/smcho/Desktop/cs/namespace/IronPython.dll, type System.Runtime.CompilerServices.ExtensionAttribute
Can't find custom attr constructor image: /Users/smcho/Desktop/cs/namespace/IronPython.dll mtoken: 0x0a000080
Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
Could not load file or assembly 'Microsoft.Scripting.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
...
IronPython.Modules.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.dll
Microsoft.Scripting.Core.dll
Microsoft.Scripting.Debugging.dll
Microsoft.Scripting.ExtensionAttribute.dll