IronRuby - how to require .NET assemblies without strong name?
Asked Answered
A

2

5

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.

Amethyst answered 3/2, 2010 at 17:36 Comment(0)
A
2

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

Amethyst answered 3/2, 2010 at 20:52 Comment(0)
S
7

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 :-)

Salinas answered 28/2, 2010 at 19:55 Comment(2)
Thanks - it's interesting to see how the IronRuby folk implemented this.Amethyst
I had a different problem, and using load_assembly fixed it. Where can I find more details on the differences between require and load_assembly?Maraca
A
2

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

Amethyst answered 3/2, 2010 at 20:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.