[英]Mono CSharp Compiler Error with Gotos
我正在使用Mono.CSharp.Evaluator的实例来编译一些代码并返回一个函数。 在我使用goto之前,它一直没有问题。 我正在使用VS2012为.NET 4.5进行构建。 我正在通过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;
});
我正在获取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()
我正在这样设置评估程序(_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;");
是否有人有解决此问题的想法?
谢谢,本
经过一番摆弄之后,我通过更改为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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.