[Ironpython-users] Loading python compiled with clr.CompileModule

Josiah Kiehl jkiehl at riotgames.com
Tue Apr 3 17:53:21 EDT 2018

Sorry if I'm not understanding... when you say "full framework version", do
you mean the stand alone executable, ipy.exe?

I compiled the dll with ipy.exe running a simple script:

> ipy compile.py

# compile.py
import clr

clr.CompileModules("compiled.dll", "test.py")

This works just fine.

Then I tried to load "compiled.dll" via the embedded IronPython in a simple
dotnet CLI app and it produces the above error:

ScriptEngine engine = Python.CreateEngine();
var scope = engine.Runtime.ImportModule("test");

Is that what's not supported? Loading the dll in the embedded IronPython?

Thanks for your help, I am super hopeful I can get this working.

On Tue, Apr 3, 2018 at 2:39 PM Stéphane Lozier <stephane.lozier at gmail.com>

> The .NET Core version of IronPython does not support assembly generation.
> I haven't tried it myself, but you could probably compile the assembly
> using the full framework version and then run it with .NET Core 2.0
> (assuming you're not using unsupported APIs).
> Stéphane
> On Tue, Apr 3, 2018, 5:16 PM Josiah Kiehl, <jkiehl at riotgames.com> wrote:
>> Oh, I'm on dotnet 2.0.3, if that's relevant information.
>> On Tue, Apr 3, 2018 at 2:15 PM Josiah Kiehl <jkiehl at riotgames.com> wrote:
>>> I'm trying to execute this example code:
>>> https://stackoverflow.com/questions/32639893/call-dll-function-from-c-sharp-ironpython
>>> I realize the posted question is a few years old at this point... has
>>> something changed in how python, compiled to a DLL via clr.CompileModule,
>>> is loaded?
>>> I'm getting this error when I run the code in the example at the above
>>> link:
>>> Unhandled Exception: System.TypeLoadException: Could not load type
>>> 'System.Runtime.CompilerServices.Closure' from assembly 'System.Core,
>>> Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
>>>    at DLRCachedCode.test$1(CodeContext $globalContext, FunctionCode
>>> $functionCode)
>>>    at IronPython.Compiler.OnDiskScriptCode.Run()
>>> (full stack:
>>> https://gist.github.com/capoferro/5a730088582b8cd36591be510d6ca2fc)
>>> My ipy.exe, which did the compilation, is and my embedded
>>> IronPython is, though I get the same error on
>>> Am I missing something obvious or is there a better example to use?
>>> My end goal is to be able to take a python module defined in a file
>>> (foo.py) with some functions defined, compile it into a dll via
>>> CompileModule, then load it directly from the dll via ImportModule to skip
>>> the performance hit of interpreting the Python at runtime.
>>> Thanks!
>>> Josiah
>>> _______________________________________________
>> Ironpython-users mailing list
>> Ironpython-users at python.org
>> https://mail.python.org/mailman/listinfo/ironpython-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20180403/7d8eb637/attachment.html>

More information about the Ironpython-users mailing list