I have a C# program to execute an IronRuby script. But before doing that, I\'d like to compile the file first to see if there is any errors. But it seems the ErrorListener does
What you're trying to do seems to not actually work. Not sure if it's a bug or not, though.
To workaround it, just execute the code inside a try/catch block and look for MissingMethodExecption. Pay attention that this also will not help if the syntax error is inside a method since IronRuby (or any other dynamic language) doesn't do anything with "nested" code until it actually executes it.
So in general, I think you won't get a lot of value from what you're trying to do.
The try/catch code sample:
ScriptEngine engine = null;
engine = Ruby.CreateEngine(x => { x.ExceptionDetail = true; });
ScriptSource sc = engine.CreateScriptSourceFromFile("MainForm.rb");
ErrorListener errLis = new MyErrorListener();
sc.Compile(errLis);
try
{
dynamic d = sc.Execute();
}
catch (MissingMethodException e)
{
Console.WriteLine("Syntax error!");
}