[Ironpython-users] Integrating a WPF IPy program with C#

Markus Schaber m.schaber at codesys.com
Tue Nov 4 12:45:03 CET 2014

Hi, Matthew,

I think for loading the DLL, you could also use the clr module from python, it has functions like AddReference, AddReferenceToFile, AddReferenceByName and AddReferenceByPartialName.

The STA thread is always necessary for WPF and Windows Forms, AFAIK, and it has to be set at the main entry function. There’s nothing one can do later (once the application is running) about this…

Best regards

Markus Schaber

CODESYS® a trademark of 3S-Smart Software Solutions GmbH

Inspiring Automation Solutions
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50

E-Mail: m.schaber at codesys.com<mailto:m.schaber at codesys.com> | Web: codesys.com<http://www.codesys.com> | CODESYS store: store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
Von: Ironpython-users [mailto:ironpython-users-bounces+m.schaber=codesys.com at python.org] Im Auftrag von Love, Matthew
Gesendet: Dienstag, 4. November 2014 11:48
An: Slide
Cc: ironpython-users at python.org
Betreff: Re: [Ironpython-users] Integrating a WPF IPy program with C#

I got it sorted in the end. I’ll post what I did for completion.

To run programs that depended on WPF, two things were needed.

First, had to load the wpf dll manually into the IronPython engine’s runtime.

var wpf_path = @"C:\Program Files (x86)\IronPython 2.7\DLLs\IronPython.Wpf.dll";
var wpf_dll = Assembly.LoadFile(wpf_path);

Secondly, make the main function a STA Thread. I put this just before Main’s definition.

static void Main(string[] args)

Hope this helps anyone in the future,

From: Slide [mailto:slide.o.mix at gmail.com]
Sent: Monday, November 03, 2014 5:51 PM
To: Love, Matthew
Cc: ironpython-users at python.org<mailto:ironpython-users at python.org>
Subject: Re: [Ironpython-users] Integrating a WPF IPy program with C#

It might help if you provide some code in a gist or something. Without that, its going to be difficult for anyone to help.

On Mon, Nov 3, 2014 at 6:32 AM, Love, Matthew <Matthew.Love at analog.com<mailto:Matthew.Love at analog.com>> wrote:
Hi IronPython users,

I’ve created a C# program that runs an IronPython script.
The script contains a GUI built in WPF.

When I call it using the IronPython Engine in C#,
I get the following error: “ImportError: No module named wpf”

I’ve pointed the Engine to the system path.

System.dll and mscorlib.dll have been loaded using the following code:

Does anyone know where I’m going wrong and how I can sort out this import?

I’m on IPy 2.7.4.


Ironpython-users mailing list
Ironpython-users at python.org<mailto:Ironpython-users at python.org>

Website: http://earl-of-code.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20141104/914fb37b/attachment.html>

More information about the Ironpython-users mailing list