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://www.mail-archive.com/[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.
In VS just Save As and next to the save button there is a drop down arrow, Select Save with Encoding…. Sorts that out.
Hi Toby, I should have mentioned, but I was using VS2010, and this is not currently available 🙁
I raised http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=390683 – Not sure if it’s something i’m doing or VS2010
However, that should work in VS2008 – thanks