c# – 为什么我不能使用Mono的Evaluator编译LINQ语句?

我正在尝试使用MS .NET框架中Mono项目的C#-Evaluator.简单的表达式编译运行正常.例如:

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

一旦我引入任何LINQ语句,我就会遇到异常.例如:

        // 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());");

错误是:

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

我做错了什么吗?或者Mono评估员显然还没有准备好使用?

最佳答案 只需删除以下代码行:

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

这不是必要的,因为您已经通过使用指令引用了它.

点赞