[IronPython] Loading IronPython.dll from memory
jslutter at reactorzero.com
Wed Dec 17 18:17:10 PST 2008
I snipped a little extra - my code is really:
Dictionary<string, object> runtimeOptions = new Dictionary<string,
runtimeOptions["Debug"] = true;
m_runtime = IronPython.Hosting.Python.CreateRuntime(runtimeOptions);
m_runtime.LoadAssembly(typeof(String).Assembly); // Add reference to System
m_runtime.LoadAssembly(typeof(Uri).Assembly); // Add reference to mscorlib
m_engine = m_runtime.GetEngine("Python");
I've also tried replacing the above with:
m_engine = Python.CreateEngine();
and I get the same exception in the call to Python.CreateEngine()
(Note: the exception exists without all the extra LoadAssemblys and
stripped to the bone).
Michael Foord wrote:
> Jeff Slutter wrote:
>> [I can work around this, but I'm curious if there is a solution]
>> Due to some crazy requirements, I'm trying to load my assemblies from
>> memory. I have setup an Assembly Resolver with:
>> AppDomain.CurrentDomain.AssemblyResolve += new
>> And it gets called. Inside the ResolveInternalAssembly I do the
>> 1) check my Dictionary to see if I have already loaded the assembly, if
>> so I return it, otherwise...
>> 2) I, currently, open the file, read in the file to byte and then call
>> 3) AppDomain.CurrentDomain.Load(asmbytes) to load the Assembly, store it
>> to the dictionary and return it.
>> This works well and all until I get to the following code within one of
>> my loaded assemblies:
>> m_engine = m_runtime.GetEngine("Python");
> Is this using the IronPython hosting API? That doesn't look like code
> that would have worked with any recent version of IronPython.
> engine = Python.CreateEngine();
>> It throws an exception saying:
>> Type 'IronPython.Runtime.PythonContext' doesn't provide a suitable
>> public constructor or its implementation is faulty: The type initializer
>> for 'IronPython.Runtime.SysModule' threw an exception.
>> I assume this is some sort of security/permissions problem because that
>> is the main thing that is different when loading an assembly from memory
>> than file.
>> My work around is to pre-load the IronPython.dll assembly before hooking
>> up my AssemblyResolve (its the only one I have to 'preload')
>> dynamicAssemblyHash["IronPython"] =
>> Any ideas?
>> Users mailing list
>> Users at lists.ironpython.com
More information about the Users