0

I have a C# piece that generates a DLL which I'm trying to invoke from Python. The C# prototype is as follow:

public Main(NationalInstruments.TestStand.Interop.API.SequenceContext sequenceContext){
    public void ShowFullOptions(out bool errorOccurred, out int errorCode, out String errorMsg) {
        [...]
    }
}

I followed this post which explains how to achieve to pass "out" parameters from python, without success since clr.Reference does not exist and throw me the error:

AttributeError: module 'clr' has no attribute 'Reference'

I have pythonnet installed, version 2.3.

My python code:

import clr

dll_path = R"thatDllPath.dll"
clr.AddReference(dll_path)

from Flamenco_Calibration_Interface import Main
import System

my_instance = Main(None)
v1 = clr.Reference[System.Boolean](False)
v2 = clr.Reference[System.Int64](1)
v3 = clr.Reference[System.String]("")

a = my_instance.ShowFullOptions(v1,v2,v3)

I have checked that the DLL path is good and I am able to successfully call the C# method if I overload "ShowFullOptions" with a version without any arguments. The main problem resides in that I have the "out" keyword in the C# method prototype.

How do you properly generate argument in python so they are accepted as "out" within C# ?

Any help much appreciated.

4
  • yes? what is the question? Commented Jun 4, 2020 at 12:03
  • python + net. you can give a try to: ironpython.net Commented Jun 4, 2020 at 12:04
  • A main function has to be compatible with the windows operating system and needs a parameter list Main(string[] args). arg[0] windows will assign the name of the program and the parameters are strings like in a command line. You can also pass data through standard input and standard output. Commented Jun 4, 2020 at 12:19
  • I cannot change the prototype since that C# piece was originally designed to be called from within TestStand (LabView world). Although the main prototype is not as you say I managed to call it using None as unique argument. Commented Jun 4, 2020 at 12:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.