IronPython: adding references from host application
Asked Answered
B

1

6

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

Boob answered 17/4, 2013 at 19:54 Comment(0)
A
8

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

engine.Runtime.LoadAssembly(typeof(System.Web.HttpContext).Assembly);
Aback answered 17/4, 2013 at 23:56 Comment(1)
thank you! somewhy i didn't guess to look into runtime of the engineBoob

© 2022 - 2024 — McMap. All rights reserved.