[IronPython] FunctionEnvironment16Dictionary problems with IronPythonStudio

Curt Hagenlocher curt at hagenlocher.org
Sun Oct 5 21:15:57 CEST 2008

Unfortunately, it's currently much easier to use C# (or "native CLS") code
from within IronPython than it is to use IronPython from within C#.  To do
this properly, you'll generally need to use the hosting interfaces -- and
they've changed pretty dramatically between 1.1 and 2.0, so you'll also need
to decide which of the two you're targeting.

There's some information about the hosting interfaces at the IronPython
Cookbook: http://www.ironpython.info/index.php/Main_Page

The simplest way to call IronPython from C# today is to define an interface
from C# and to have your Python class derive from it.  But you'd still have
the issue of being able to instantiate the object.

On Sun, Oct 5, 2008 at 11:25 AM, <sefirah6990 at katamail.com> wrote:

> Hi,
> I'm new to IronPythonStudio. I choose this environment in order to create
> .NET assemblies (dll) from IronPython code and use them into a .NET project
> (like C#, J# or so).
> I've noticed that some conversions between IP code and compiled dll were
> made by IronPythonStudio compiler, for example the names of every
> user-defined method change from "methodName" to "MethodName$f19" (a suffix
> like "$f<random number>" is appended)..no problems about that.
> The convertion that is causing me a lot of troubles is about method
> parameters.
> Example: if my init method was:
>  __init__(self, n, s, m)
> after compilation becomes:
> __init__$f0(FunctionEnvironment16Dictionary _env, Object self, Object n,
> Object s, Object m)
> Well, where should i get the correct instance of
> FunctionEnvironment16Dictionary?
> If i create a new object of this type and try to invoke init in this way:
> (now we are into a C# project)
> Student stu2 = new Student();
> stu2.__init__$f0(new FunctionEnvironment16Dictionary(), stu2, "hello",
> "world", "!!!");
> the system always throw a NullReferenceException in the second line.. Here
> is the stack trace:
>   at IronPython.Runtime.Calls.FunctionEnvironmentDictionary.get_Module()
>   at IronPython.Runtime.Operations.Ops.UpdateTraceBack(ICallerContext
> context, String filename, Int32 line, String funcName, Boolean& notHandled)
>   at Student.__init__$f0(FunctionEnvironment16Dictionary $env, Object self,
> Object n, Object s, Object m)
>   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
>   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
> assemblySecurity, String[] args)
>   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
>   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
>   at System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state)
>   at System.Threading.ThreadHelper.ThreadStart()
> Seems that a Module is required but i don't understand what should i do...
> Someone could explain where is my mistake?
> Thanks a lot!!
> Marco
> ---- Nuova grafica e nuove funzionalità! Crea subito Gratis la tua nuova
> Casella di Posta  Katamail
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081005/88f9d8d8/attachment.html>

More information about the Ironpython-users mailing list