2013-11-20 39 views
1

我正在使用Mono.CSharp.Evaluator的一个实例来编译一些代码并返回一个函数。在我使用goto之前它一直没有问题。我正在用VS2012构建.NET 4.5。我正在通过Evaluator.Evaluate下面的代码,并在对象存储,以便以后执行:Mono CSharp Compiler Error with Gotos

 Func<Dictionary<string, object>, dynamic, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod, AddResultWrapperMethod, int> a = new Func<Dictionary<string, object>, dynamic, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod, AddResultWrapperMethod, int>((parameters, self, debug, log, warn, error, exception, addResult) => 
     { 

      Console.WriteLine("beforegoto"); 
      goto Ben; 
     Ben: 
      Console.WriteLine("gotoResult"); 
      return 0; 

     }); 

我越来越InternalErrorException((1,1):) 的的InnerException是

坏标签在的ILGenerator

at System.Reflection.Emit.ILGenerator.GetLabelPos(Label lbl) 
at System.Reflection.Emit.ILGenerator.BakeByteArray() 
at System.Reflection.Emit.MethodBuilder.CreateMethodBodyHelper(ILGenerator il) 
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() 
at System.Reflection.Emit.TypeBuilder.CreateType() 
at Mono.CSharp.TypeDefinition.CloseContainer() 

我这样

 _settings = new CompilerSettings 
         { 
          EnhancedWarnings = true, 
          Stacktrace = true, 
          ShowFullPaths = true, 
          Timestamps = true, 
          Optimize = true, 
          AssemblyReferences = new List<string> 
                { 
                 "Microsoft.CSharp.dll" 
                }, 
         }; 
     _ctx = new CompilerContext(_settings, new Reporter()); 
     _e = new Evaluator(_ctx); 
     _e.Run("using System;"); 
     _e.Run("using System.Collections.Generic;"); 
     _e.Run("using System.Dynamic;"); 
     _e.Run("using System.Linq;"); 
     _e.Run("using System.Text.RegularExpressions;"); 
0设立评估程序(_E)含量

有没有人有任何想法如何解决这个问题?

感谢, 本

+0

您的匿名功能之外是否有另一个名为'Ben'的标签? –

+0

我已经加倍检查过了,而且我不需要 – user2849000

+1

[报告错误](https://bugzilla.xamarin.com/enter_bug.cgi?classification=__all)最有可能让您更好。他们非常敏感。 –

回答

0

一些摆弄后,我通过改变Evaluator.Run,​​稍微改变运行代码,然后运行Evaluator.Evaluate修复了这个问题。修改后的代码如下

_e.Run("object o = Func<Dictionary<string, object>, dynamic, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod, AddResultWrapperMethod, int> a = new Func<Dictionary<string, object>, dynamic, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, LogWrapperMethod, ExcWrapperMethod, AddResultWrapperMethod, int>((parameters, self, debug, log, warn, error, exception, addResult) => 
    { 

     Console.WriteLine(\"beforegoto\"); 
     goto Ben; 
    Ben: 
     Console.WriteLine(\"gotoResult\"); 
     return 0; 

    });"); 
object func = _e.Evaluate("o");