43

単純なhelloworldを実行して、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

ターゲットの.NETFrameworkは4.0で、IronPython2.6を使用しています。

これを実行すると、「CSC」というファイルから2つのエラーが発生します。エラー5コンパイラに必要なメンバーがありません

'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember' C:\ Users \ Tolga \ document \ visual studio 2012 \ Projects \ WindowsFormsApplication1 \ consoleTest \ CSC consoleTest

もう1つは、私が作成したC#ファイルからのものです

エラー6動的式のコンパイルに必要な1つ以上のタイプが見つかりません。参照がありませんか?C:\ Users \ Tolga \ document \ visual studio 2012 \ Projects \ WindowsFormsApplication1 \ consoleTest \ Program.cs 17 9 consoleTest

これがビルドからの出力です

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 ==========
4

3 に答える 3

119

への参照を追加する必要がありますMicrosoft.CSharp.dll。これにより、dynamicC#で使用するために必要なタイプが提供されます。

また、古いリリースや新しい.NETフレームワークとの互換性がないため、IronPython2.7[.3]以降にアップグレードする必要があります。

于 2012-10-01T17:54:48.410 に答える
3

間違ったターゲットアセンブリへの参照を含めた場合にも、このエラーが発生します。たとえば、.Net 4.0 Fullプロファイルに対してビルドする場合は、以下のIronPythonアセンブリを含める必要があります。

<install directory>\IronPython 2.7\Platforms\Net40

ディレクトリからアセンブリを含めるNet35と、欠落RuntimeBinderエラーが発生します。

于 2013-12-10T18:17:33.833 に答える
0

新しいプロジェクトでIronPython2.7.10を使用して今朝直面した、まだ存在している問題に対する非常に古い質問。

受け入れられた回答を改善できるようになりました。Microsoft.CSharp.dllを手動で追加する代わりに、nugetからパッケージ「Microsoft.CSharp」を追加することをお勧めします。移植性が向上します(netstandard、net Framework、netcore ...)。

于 2020-05-05T09:00:42.480 に答える