I just ran head first into a wall I wasn’t expecting. I was attempting to host the DLR within a C# application (topic for another host), the IronRuby code I wanted to load was in an external file and was simply:
puts ‘Hello World’
However, when I attempted to load the file, I was greeted with an unhandled exception.
Microsoft.Scripting.SyntaxErrorException was unhandled
Message=”Invalid character ‘ï’ in expression”
SourceCode=”ï»¿def helloWorld()rn puts ‘Hello World’rnend”
SourcePath=”C:/Users/Administrator/Documents/Visual Studio 10/Projects/IronRubyHost/bin/DebughelloWorld.rb”
at Microsoft.Scripting.ErrorSink.Add(SourceUnit source, String message, SourceSpan span, Int32 errorCode, Severity severity) in E:IronRubyr156srcMicrosoft.ScriptingErrorSink.cs:line 34
at Microsoft.Scripting.ErrorCounter.Add(SourceUnit source, String message, SourceSpan span, Int32 errorCode, Severity severity) in E:IronRubyr156srcMicrosoft.ScriptingErrorSink.cs:line 92
at IronRuby.Compiler.Tokenizer.Report(String message, Int32 errorCode, SourceSpan location, Severity severity) in E:IronRubyr156srcironrubyCompilerParserTokenizer.cs:line 430
I was surprised to see the additional characters being added to the start of my SourceCode. After a bit of searching, I found this:
It turns out that Ruby 1.8 (which IronRuby is targeting) doesn’t have support for Unicode characters. When creating a text file using Visual Studio, it automatically saves it with unicode support.
The quickest solution appears to be that you shouldn’t use Visual Studio to create Ruby files – at least until the editor has IronRuby integration. The other solution would be to use another editor, for example GVim or IronEditor, which is shortly going to get a facelift.