Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IronPython: adding references from host application

Tags:

c#

ironpython

In my application I'm using Iron Python to provide scripting capabilities. The problem is that embedded scripts don't see references I've linked to the app. Only solution as I understand is to manually import them from script

import clr
clr.AddReference(...)
from ... import ...

but I'm reading scripts from files and I don't want to prepend a bunch of imports like this. So how do I add references from host application? ScriptEngine / ScriptScope doesn't look to have any related methods :(

like image 816
Daniel Avatar asked Apr 17 '13 19:04

Daniel


1 Answers

The method you want is ScriptRuntime.LoadAssembly, easily accessed from your ScriptEngine instance:

engine.Runtime.LoadAssembly(typeof(System.Web.HttpContext).Assembly);
like image 71
Jeff Hardy Avatar answered Sep 22 '22 09:09

Jeff Hardy