I am using an instance of Mono.CSharp.Evaluator to compile some code and return a function. It has worked without issue until I used a goto. I am building for .NET 4.5 with VS2012. I am running the following code through Evaluator.Evaluate, and storing it in an object for later execution:
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
Bad label content in 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
_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