[IronPython] Compile IronPython Script to EXE on Linux
Dino Viehland
dinov at microsoft.com
Mon Apr 26 22:27:30 CEST 2010
Ben wrote:
> OS: Ubuntu 9.10 using IronPython PPA
> https://launchpad.net/~gezakovacs/+archive/ironpython
> IronPython Version: IronPython 2.6 Beta 2 DEBUG (2.6.0.20) on .NET
> 2.0.50727.1433
> Mono Version: Mono JIT compiler version 2.4.4 (Debian
> 2.4.4~svn151842-1gezakovacs~karmic1)
>
> I'm having trouble compiling any IronPython script to EXE on Linux.
> The scripts compile fine on IronPython2.6 on Windows. The DLL
> generated by the script before the exe step seems correct.
>
> I am using the pyc.exe script downloaded from:
> http://ironpython.codeplex.com/sourcecontrol/network/Show?projectName=IronPyth
> on&changeSetId=65328#991948
>
> I am using a command like: ipy pyc.exe /main:hello.py /target:exe
>
> The error is: SystemError: Method is not VarArgs method and optional
> types were passed
>
> And it comes on this line: gen.EmitCall(OpCodes.Call,
> clr.GetClrType(Assembly).GetMethod("GetEntryAssembly"), ())
>
> The simplest example script is:
> import clr
> print "Hello world"
This looks like a Mono bug but it appears to be fixed in the latest version of Mono.
This small program demonstrates the issue:
using System;
using System.Reflection;
using System.Reflection.Emit;
class Test {
public static void Main(string[] args) {
var asm = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("test"), AssemblyBuilderAccess.Save);
var mod = asm.DefineDynamicModule("test.dll");
var type = mod.DefineType("Test");
var method = type.DefineMethod("TestMethod", MethodAttributes.Public | MethodAttributes.Static);
var ilgen = method.GetILGenerator();
ilgen.EmitCall(OpCodes.Call, typeof(Assembly).GetMethod("GetEntryAssembly"), new Type[0]);
type.CreateType();
asm.Save("test.dll");
}
}
Mono (2.4.2.3) reports:
Unhandled Exception: System.InvalidOperationException: Method is not VarArgs method and optional types were passed
at System.Reflection.Emit.ILGenerator.EmitCall (OpCode opcode, System.Reflection.MethodInfo methodInfo, System.Type[] optionalParameterTypes) [0x00000]
at Test.Main (System.String[] args) [0x00000]
Even though the argument array of types is empty. But it works just fine on Mono 2.6.3 for me.
If you can't/don't want to upgrade Mono you can change the EmitCall line to:
ilgen.Emit(OpCodes.Call, typeof(Assembly).GetMethod("GetEntryAssembly"));
And it works fine. The similar change to pyc should be:
gen.Emit(OpCodes.Call, clr.GetClrType(Assembly).GetMethod("GetEntryAssembly"))
More information about the Ironpython-users
mailing list