[IronPython] Referencing extension modules from hosting

Jeff Hardy jdhardy at gmail.com
Thu Mar 18 17:31:01 CET 2010

When using a C# PythonModule, there seem to be two ways to load it:
from script using clr.AddReference and into the console by dropping it
into the DLLs folder. However, there doesn't seem to be a
straightforward way to load them in a hosting scenario.

The best way I've found is the following:

string zlibModule = "IronPython.Zlib.dll"
object addRef = engine.GetClrModule().GetVariable("AddReference");
Assembly zlib = Assembly.LoadFile(zlibFile);
engine.Operations.Invoke(addRef, zlib);

It's not terribly difficult to write, but it would be nice to have an
extension method on ScriptEngine that did it.

In a similar vein, it would be nice if the engine could scan the
current AppDomain for assemblies that contain PythonModules - this
would be useful when running under ASP.NET, as it references an
assemblies in its bin/ folder, and having them automatically available
would be handy.

Finally, it would be nice to have an extension method on ScriptScope -
ImportModule? - that did the equivalent of

scope.SetVariable("zlib", scope.Engine.ImportModule("zlib"));

If these suggestions are useful I'll create issues for them.

- Jeff

P.S. These are the sorts of things it would be nice to be able to
contribute patches for.

More information about the Ironpython-users mailing list