我正在尝试做一个简单的 hello world 来测试在 C# 中嵌入 IronPython,但似乎无法解决这个问题。
这是我的 C# 文件;
using System;
using IronPython.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using System.IO;
public class dynamic_demo
{
static void Main()
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile(@"../../Test.py");
test.Simple();
}
}
这是python类;
import sys
def Simple():
print 'Hello from Python'
print "Call Dir(): "
print dir()
print "Print the Path: "
print sys.path
我的目标 .NET 框架是 4.0,我正在使用 IronPython 2.6..
当我运行这个来自一个名为“CSC”的文件时,我得到 2 个错误;错误 5 缺少编译器所需的成员
'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember' C:\Users\Tolga\documents\visual studio 2012\Projects\WindowsFormsApplication1\consoleTest\CSC consoleTest
另一个来自我创建的 C# 文件
错误 6 找不到编译动态表达式所需的一种或多种类型。您是否缺少参考?C:\Users\Tolga\documents\visual studio 2012\Projects\WindowsFormsApplication1\consoleTest\Program.cs 17 9 控制台测试
这是构建的输出
1>------ Build started: Project: consoleTest, Configuration: Debug Any CPU ------
1>CSC : warning CS1685: The predefined type 'System.Runtime.CompilerServices.CallSite' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files (x86)\IronPython 2.6\Microsoft.Scripting.Core.dll'
1>CSC : warning CS1685: The predefined type 'System.Runtime.CompilerServices.CallSite' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files (x86)\IronPython 2.6\Microsoft.Scripting.Core.dll'
1>CSC : warning CS1685: The predefined type 'System.Runtime.CompilerServices.CallSiteBinder' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files (x86)\IronPython 2.6\Microsoft.Scripting.Core.dll'
1>CSC : warning CS1685: The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll'
1>CSC : error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'
1>C:\Users\Tolga\documents\visual studio 2012\Projects\WindowsFormsApplication1\consoleTest\Program.cs(17,9,17,20): error CS1969: One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========