1

I am trying to execute a Python Script on a C# Application. So I choose Iron Python, I have managed to execute basic code.

But while using libraries like xml or json. I cannot import and use them. I've tried a lot,but nothing works out.

The main thing which I tried was to copy the xml librairy in my C# project folder, and then import it using the following code:

import clr
clr.AddReferenceToFileAndPath("..\\ElementTree.py")
import ElementTree as ET
clr.AddReferenceToFileAndPath("..json\\__init__.py")
import json

But i get this error :

System.BadImageFormatException: 'The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)'

Can someone provide me a with a good solution?

If you need more details, please comment the question.

Thanks in advance

cezar
  • 11,616
  • 6
  • 48
  • 84
Axel
  • 165
  • 3
  • 14
  • Those methods load *.NET assemblies* not Python scripts – Panagiotis Kanavos Apr 26 '18 at 12:42
  • Why do you want to do this? You can just execute files for simple stuff. Like here https://stackoverflow.com/questions/11779143/how-do-i-run-a-python-script-from-c Somewhere... I think I have some code uses ironython for dynamic processing. – Andy Apr 26 '18 at 15:00
  • I need to execute python code in c# and this python code uses XML and JSON. Isnt IronPython a good solution to do this? Is there other better solution? Sorry to be so late on the response, i was working on somthing else and forgot this post. – Axel May 03 '18 at 11:48

0 Answers0