Microsoft.Scripting.SyntaxErrorException was unhandled – Unicode support and IronRuby

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:

def helloWorld()
   puts ‘Hello World’
end

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”
  Source=”Microsoft.Scripting”
  Column=2
  ErrorCode=4112
  Line=1
 
SourceCode=”def helloWorld()rn   puts ‘Hello World’rnend”
  SourcePath=”C:/Users/Administrator/Documents/Visual Studio 10/Projects/IronRubyHost/bin/DebughelloWorld.rb”
  StackTrace:
       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:

http:[email protected]/msg02137.html

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.

Technorati Tags: ,

2 thoughts on “Microsoft.Scripting.SyntaxErrorException was unhandled – Unicode support and IronRuby”

Leave a Reply

Your email address will not be published. Required fields are marked *