Problems embedding IronPython in C# (Missing Compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'

Question:

I’m trying to do a simple hello world to test out embedding IronPython within C# but can’t seem to resolve this problem..

This is my C# file;

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();
    }
}

And this is the python class;

import sys

def Simple():
    print 'Hello from Python'
    print "Call Dir(): "
    print dir()
    print "Print the Path: " 
    print sys.path

My target .NET framework is 4.0 and I’m using IronPython 2.6..

I get 2 errors when I run this one is from a file called “CSC”;
Error 5 Missing compiler required member

‘Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember’ C:UsersTolgadocumentsvisual
studio
2012ProjectsWindowsFormsApplication1consoleTestCSC consoleTest

The other one is from C# file i created

Error 6 One or more types required to compile a dynamic expression
cannot be found. Are you missing a
reference? C:UsersTolgadocumentsvisual studio
2012ProjectsWindowsFormsApplication1consoleTestProgram.cs 17 9 consoleTest

Here’s the output from the 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.6Microsoft.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.6Microsoft.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.6Microsoft.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 AssembliesMicrosoftFramework.NETFrameworkv4.5mscorlib.dll'
1>CSC : error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'
1>C:UsersTolgadocumentsvisual studio 2012ProjectsWindowsFormsApplication1consoleTestProgram.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 ==========
Asked By: Tolga E

||

Answers:

You need to add a reference to Microsoft.CSharp.dll. This provides the required types for using dynamic in C#.

Also, you will likely need to upgrade to IronPython 2.7[.3] or later, as there are some incompatibilities with old releases and the newer .NET frameworks.

Answered By: Reed Copsey

You will also get this error if you’ve included references to the wrong target assemblies. For instance, if you’re building against the .Net 4.0 Full profile, you must include the IronPython assemblies from:

<install directory>IronPython 2.7PlatformsNet40

Including assemblies from the Net35 directory will also result in the missing RuntimeBinder error.

Answered By: cod3monk3y

Very old question for a still existing issue I’ve faced this morning using IronPython 2.7.10 in a new project.

The accepted answer can now be improved : instead of manually adding Microsoft.CSharp.dll, I would recommend adding the package “Microsoft.CSharp” from nuget. Portability will be improved (netstandard, net framework, netcore…).

Answered By: Tok'
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.