简体   繁体   中英

Calling C# functions from IronPython

I have aa library (.dll) of C# function()s, that I want to invoke from IronPython. An example shown here - CMD_Handshake() - is defined in a , takes no arguments, and returns a boolean...

thusly,

    public bool CMD_Handshake()
    {
        .
    .
    return (Send(out b_handshake_code));

    }

[from IronPython]

clr.AddReferenceToFileAndPath() successfully adds the .dll references.

The is successfully imported. The class is successfully imported. CMD_Handshake() is recognized as a method of the class "App" is the instantiation of the class.

HOWEVER: when I invoke the function, I receive the following error message from Python:

App.CMD_Handshake() Traceback (most recent call last): File "", line 1, in TypeError: CMD_Handshake() takes exactly 1 argument (0 given)

(I feel like I'm soooo... close.)

The issue is that bool CMD_Handshake() is an instance method and not a static one. This means you should create an instance of App and call the method on it:

app = App()
app.CMD_Handshake()

TypeError: CMD_Handshake() takes exactly 1 argument (0 given)

This error is due to the fact that you are calling an instance method as a static method and thus it expects an instance of App as its first argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM