views:

259

answers:

2

This page on the IronRuby help website talks about being able to 'require' some well-known assemblies such as System.Windows.Forms without needing to crank out the entire 'ah-come-on-gimme-a-break-here-you-cannot-be-serious' strong name of the assembly.

In the docs it says this:

>>> require "System.Windows.Forms"  
=> true  

But when I try the same 'require', I get this:

>>> require "System.Windows.Forms"
IronRuby.Libraries:0:in 'require': no such file to load -- System.Windows.Forms (LoadError) 
        from :0:in 'Initialize##1'

What might I be doing wrong? Could it be a setup problem? I can't see this "libs directory on the load path" that gets mentioned in the documentation. Is the documentation wrong?

Thanks.

+1  A: 

Well, it was a setup problem - there were two copies of ir.exe in the IronRuby download, and I was using the wrong one.

mackenir
+3  A: 

The way that this works is because the IronRuby guys have written a bunch of wrapper scripts.

Look in <your ironruby install path>\lib\ironruby and you'll see System.Windows.Forms.rb, System.Drawing.rb etc.

What happens when you do require 'System.Windows.Forms' is that IronRuby finds that rb file and runs it. The code inside that file just does the full strong-named require for you.

If you want to load other dll's that they haven't written wrappers for, you have 3 options:

  1. require the full path to the dll (eg c:\program files\whatever\whatever\blah.dll)

  2. require the strong name (this only works if it's in the GAC or somewhere else IronRuby can find dll's in)

  3. use load_assembly - This is the most convenient, but IIRC it loads the dll into the LoadFrom context, not the Load context.
    If you don't understand what that means, then basically it's fine in testing, but don't do it in production :-)

Orion Edwards
Thanks - it's interesting to see how the IronRuby folk implemented this.
mackenir