IronRuby with StreamReader and StreamWriter

While playing around with IronRuby, I wanted to access a stream, as such I needed to create a StreamReader.  Generally a very simple task, however no matter what I did, I was getting an error message.

The code looked like this, readStream =, however when executed I was always getting the error.

E:IronRubysrcIronRuby.LibrariesBuiltinsModuleOps.cs:721:in `const_missing’: uninitialized constant System::IO:
:StreamReader (NameError)

NameError means IronRuby cannot find the StreamReader object – a bit of a problem. I thought I had included all the required references, I had access to the System.dll using the correct require statement.

require ‘System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’

After firing up reflector, turns out StreamReader is actually in the mscorlib assembly – not System.dll.  This was a simple fix, I added an additional require statement for mscorlib (require ‘mscorlib’) and I could happily access the StreamReader object.

In future, I’ll remember to always reference mscorlib and system.dll when doing .Net interop – it will just make life easier.

Technorati Tags:

One thought on “IronRuby with StreamReader and StreamWriter”

  1. I am trying learn ruby through ironruby and some of your post have been helpful. The setup post was really helpful and now I just saw how to do namespacing. Thanks.

Leave a Reply

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