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 = System::IO::StreamReader.new(receiveStream), however when executed I was always getting the error.
E:IronRubysrcIronRuby.LibrariesBuiltinsModuleOps.cs:721:in `const_missing’: uninitialized constant System::IO:
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=184.108.40.206, 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.