[英]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.