[Mono-dev] DLR with Mono.CSharp.Evaluator: The predefined type Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported

Marek Safar marek.safar at gmail.com
Fri Nov 23 22:13:04 UTC 2012


Hello,

I'm currently implementing REPL functionality in my app that embeds mono
> runtime (3.0.1), and I've encountered some issues when evaluating code that
> contains dynamic invocation.
>
> For example, consider this simple dynamic class:
>
> public class Foo : DynamicObject {
> public override bool TryGetMember(GetMemberBinder binder, out object
> result) {
>  result = 5;
> return true;
> }
> }
>
> The following Evaluator initialization:
>
>         var settings = new CompilerSettings();
>         var printer = new ConsoleReportPrinter();
>         eval = new Evaluator(new CompilerContext(settings, printer));
>         eval.ReferenceAssembly(typeof(REPL).Assembly);
>         eval.Run("using System;");
>
> And the evaluation
>
>         dynamic f = new Program.Foo();
>         f.Whatever;
>
> gives following error:
>
> error CS0518: The predefined type Microsoft.CSharp.RuntimeBinder.Binder'
> is not defined or imported (1,4): error CS1969: Dynamic operation cannot be
> compiled without `Microsoft.CSharp.dll' assembly reference.
>
>
This is strange, are you embedding correct runtime version (4.0) ?

I have tried to cook full sample based on your code and it works without
error for me as a standalone app.

using System;
using System.Dynamic;
using Mono.CSharp;

public class Foo : DynamicObject
{
    public override bool TryGetMember(GetMemberBinder binder, out object
result)
    {
        Console.WriteLine("called");
        result = 5;
        return true;
    }
}

class C
{
    public static void Main()
    {
        var settings = new CompilerSettings();
        var printer = new ConsoleReportPrinter();
        var eval = new Evaluator(new CompilerContext(settings, printer));
        eval.ReferenceAssembly(typeof(Foo).Assembly);
        eval.Run("using System;");
        eval.Run("dynamic f = new Foo();");
        eval.Run("f.Whatever;");
    }
}

Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20121123/5ba3446a/attachment.html>


More information about the Mono-devel-list mailing list