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

Bartosz Przygoda bprzygoda at gmail.com
Thu Nov 22 12:04:27 UTC 2012


Hi,

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.

So I went off and added following:

eval.ReferenceAssembly(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly);

which now gave following warning:

warning CS1685: The predefined type `Microsoft.CSharp.RuntimeBinder.Binder'
is d
efined multiple times. Using definition from `Microsoft.CSharp.dll'

What I ended up using was to just use one of the types from
Microsoft.CSharp assembly in my code, before even calling Evaluator (to
force the runtime to load the types into the assembly), something like:

var r =
Microsoft.CSharp.RuntimeBinder.Binder.IsEvent(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.BinaryOperationLogical,
"gf", typeof(int)); // just do whatever involving those types

Am I missing some initialization option for Evaluator, or should I
reference Microsoft.CSharp assembly like in the above code and just ignore
the warning?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20121122/c1417141/attachment.html>


More information about the Mono-devel-list mailing list