在C#中embeddedIronPython的问题(缺less编译器所需的成员“Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember”
我试图做一个简单的Hello世界来testing在C#中embeddedIronPython,但似乎无法解决这个问题..
这是我的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 ..
当我运行这个错误时,我得到2个错误是来自一个名为“CSC”的文件; 错误5缺less编译器所需的成员
'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'C:\ Users \ Tolga \ documents \ visual studio 2012 \ Projects \ WindowsFormsApplication1 \ consoleTest \ CSC consoleTest
另一个是从我创build的C#文件
错误6无法find编译dynamicexpression式所需的一个或多个types。 你错过了一个参考吗? C:\ Users \ Tolga \ documents \ visual studio 2012 \ Projects \ WindowsFormsApplication1 \ consoleTest \ Program.cs 17 9 consoleTest
这是Build的输出
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 ==========
您需要添加对Microsoft.CSharp.dll
的引用。 这提供了在C#中使用dynamic
所需的types。
此外,您可能需要升级到IronPython 2.7 [.3]或更高版本,因为旧版本和较新的.NET框架存在一些不兼容问题。
如果您已经包含对错误的目标程序集的引用,则也会得到此错误。 例如,如果您正在构build.Net 4.0 Fullconfiguration文件,则必须从以下位置包含IronPython程序集:
<install directory>\IronPython 2.7\Platforms\Net40
包括来自Net35
目录的程序集也将导致缺lessRuntimeBinder
错误。