DfM
DfM

Reputation: 539

Python for .NET: System.BadImageFormatException when embedding

I'm trying to embed Python in my .NET application.

I'm using Python 3.6.1 64-bit on Windows 10 and I have installed pythonnet 2.3.0 from PyPi using pip.

I've referenced Python.Runtime.dll from C:\Program Files\Python36\Lib\site-packages and have both Path and PYTHONHOME environment variables pointed to C:\Program Files\Python36\.

When I use .NET in Python everything is OK.

import clr
from System.Drawing import Point
p = Point(5, 5)
print(p)

prints {X=5,Y=5} as expected.

But when I call Python from .NET I get System.BadImageFormatException. For example, when calling Python.Runtime.PythonEngine.Initialize(); :

System.BadImageFormatException: 'Could not load file or assembly 'Python.Runtime, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.'

Any thoughts?

Thanks in advance.

Upvotes: 5

Views: 2546

Answers (1)

DfM
DfM

Reputation: 539

As denfromufa said, I was just calling from a 32-bit .NET process.

Upvotes: 7

Related Questions