4

I'm trying to use the C#-Evaluator from the Mono-project in the MS .NET framework. Simple expressions compile an run fine. For example:

        var report = new Report(new Printer());
        var settings = new CommandLineParser(report).ParseArguments(new string[] { });
        var eval =  new Evaluator(settings, report);

        // ensure that the LINQ to object assembly is referenced
        eval.ReferenceAssembly(typeof(Enumerable).Assembly);

        eval.Run("using System;");
        eval.Run("using System.Collections.Generic;");
        eval.Run("using System.Linq;");

        // Runs just fine:
        eval.Run("IEnumerable<string> allData = new string[0];");
        eval.Run("Console.Out.WriteLine(allData.Count());");

As soon as I bring in any LINQ statements I get exceptions. For example:

        // Crashes:
        eval.Run("IEnumerable<string> allData = new string[0];");
        eval.Run("var filtered = from d in allData select d;");
        eval.Run("Console.Out.WriteLine(filtered.Count());");

The error is:

Internal compiler error at Internal(1,1):: exception caught while emitting Name: Host 
Attributes: 150
Method Signature: Length: 5
Arguments: 0
Signature: 
0  0  1  16  28  0  

Mono.CSharp.InternalErrorException : VariableInfo is null and the variable `filtered' is not used
at Mono.CSharp.LocalVariable.CreateBuilder(EmitContext ec) in statement.cs: line 1593
at Mono.CSharp.BlockVariableDeclaration.DoEmit(EmitContext ec) in statement.cs: line 1368
at Mono.CSharp.Statement.Emit(EmitContext ec) in statement.cs: line 69
at Mono.CSharp.Block.DoEmit(EmitContext ec) in statement.cs: line 2035
at Mono.CSharp.Block.Emit(EmitContext ec) in statement.cs: line 2045
at Mono.CSharp.ExplicitBlock.Emit(EmitContext ec) in statement.cs: line 2177
at Mono.CSharp.ToplevelBlock.Emit(EmitContext ec) in statement.cs: line 2918
at Mono.CSharp.MethodData.Emit(DeclSpace parent) in method.cs: line 2021
at Mono.CSharp.MethodOrOperator.Emit() in method.cs: line 686
at Mono.CSharp.Method.Emit() in method.cs: line 1232
at Mono.CSharp.TypeContainer.EmitType() in class.cs: line 1968
at Mono.CSharp.Evaluator.CompileBlock(Class host, Undo undo, Report Report) in eval.cs: line 659
at Mono.CSharp.Evaluator.Compile(String input, ref CompiledMethod compiled) in eval.cs: line 231
at Mono.CSharp.Evaluator.Evaluate(String input, ref Object result, ref Boolean result_set) in eval.cs: line 298
at Mono.CSharp.Evaluator.Run(String statement) in eval.cs: line 391

Am I doing something obviously wrong? Or is the Mono evaluator clearly not ready to be used?

Nate
  • 30,286
  • 23
  • 113
  • 184
Gamlor
  • 12,978
  • 7
  • 43
  • 70
  • 2
    Did you try replacing `var` with the actual type, i.e. `IEnumerable`? – Daniel Hilgarth May 02 '11 at 15:47
  • An InternalErrorException is not a good thing. You're not doing anything wrong. Please test with a fresh Mono and file a bug on bugzilla if you still experience this issue. Thanks! – Jb Evain May 02 '11 at 16:00
  • Now I've tried it. Fixes the exception and returns a compile error. A attribute from the .NET framework and the Mono assembly collide. Will check that. Thanks anyway. – Gamlor May 02 '11 at 16:02
  • @Jb Evain: Im running on the trunk/master checkout. Want first avoid any mistakes on my side before entering a bug. – Gamlor May 02 '11 at 16:04
  • Please file a bug which with code that reproduces the exception so this can be fixed properly. Thanks! – Jb Evain May 02 '11 at 16:23
  • I currently get a 500 error when trying to register a Novell account. Will report is when that works again. – Gamlor May 02 '11 at 17:19
  • Answer may be here: http://stackoverflow.com/questions/3407318/mono-compiler-as-a-service-mcs – Jeff May 02 '11 at 15:55

1 Answers1

2

Just remove the following line of code:

// ensure that the LINQ to object assembly is referenced
eval.ReferenceAssembly(typeof(Enumerable).Assembly);

It's not necessary because you referenced it already by using directives.

Florian
  • 5,918
  • 3
  • 47
  • 86