engine.ExecuteFile gives errors

I am using the following code to execute a Ruby file from C# but it
gives me the error:

var runtime = IronRuby.Ruby.CreateRuntime();
var engine = runtime.GetEngine(“rb”);

        engine.ExecuteFile("../../HelloWorld.rb");

And here is the error:

Unhandled Exception: Microsoft.Scripting.SyntaxErrorException: syntax
error, une
xpected END, expecting END_OF_FILE
at Microsoft.Scripting.ErrorSink.Add(SourceUnit source, String
message, Sourc
eSpan span, Int32 errorCode, Severity severity)
at Microsoft.Scripting.ErrorCounter.Add(SourceUnit source, String
message, So
urceSpan span, Int32 errorCode, Severity severity)
at IronRuby.Compiler.Parser.ReportSyntaxError(String message)
at IronRuby.Compiler.Parser.ErrorRecovery()
at IronRuby.Compiler.Parser.Parse()
at IronRuby.Compiler.Parser.Parse(SourceUnit sourceUnit,
RubyCompilerOptions
options, ErrorSink errorSink)
at IronRuby.Runtime.RubyContext.ParseSourceCode[T](SourceUnit
sourceUnit, Rub
yCompilerOptions options, ErrorSink errorSink)
at IronRuby.Runtime.RubyContext.CompileSourceCode(SourceUnit
sourceUnit, Comp
ilerOptions options, ErrorSink errorSink)
at Microsoft.Scripting.SourceUnit.Compile(CompilerOptions options,
ErrorSink
errorSink)

And here is the Ruby file:

class Person

def foo()
puts ‘hello world’
end

end

person = Person.new()
person.foo()

Is it possible that you’ve saved the file as UTF-8 or Unicode?

Curt H. wrote:

Is it possible that you’ve saved the file as UTF-8 or Unicode?

Well I just created a text file with “.rb” extension.

That is a problem because visual studio adds UTF-8 encoding to that
file.
I created one file in notepad and made a template from that file and I
use
that template to create new ruby files in visual studio.


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Here’s the easiest way I know how to check:

  1. Open the file in Notepad
  2. Choose “File | Save As”
  3. Look at the value for “Encoding”. If it’s anything other than “ANSI”,
    change the encoding to ANSI, save the file and try again.

Awesome guys I got it working!

Thanks a million! :slight_smile: