简体   繁体   English

Gotos的Mono CSharp编译器错误

[英]Mono CSharp Compiler Error with Gotos

I am using an instance of Mono.CSharp.Evaluator to compile some code and return a function. 我正在使用Mono.CSharp.Evaluator的实例来编译一些代码并返回一个函数。 It has worked without issue until I used a goto. 在我使用goto之前,它一直没有问题。 I am building for .NET 4.5 with VS2012. 我正在使用VS2012为.NET 4.5进行构建。 I am running the following code through Evaluator.Evaluate, and storing it in an object for later execution: 我正在通过Evaluator.Evaluate运行以下代码,并将其存储在对象中以供以后执行:

        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;

        });

I am getting InternalErrorException ((1,1): ) The InnerException is 我正在获取InternalErrorException((1,1):)InnerException是

Bad label content in ILGenerator 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()

I am setting up the Evaluator (_e) as such 我正在这样设置评估程序(_e)

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

Does anybody have any ideas how to resolve this issue? 是否有人有解决此问题的想法?

Thanks, Ben 谢谢,本

After some fiddling, I fixed this issue by changing to Evaluator.Run, changing the run code slightly, and then running Evaluator.Evaluate. 经过一番摆弄之后,我通过更改为Evaluator.Run,​​稍微更改运行代码然后运行Evaluator.Evaluate来解决了此问题。 Revised code below 修改后的代码如下

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM