onch
onch

Reputation: 43

Calling C# functions from IronPython

I have a a 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.)

Upvotes: 2

Views: 632

Answers (1)

Jaanus Varus
Jaanus Varus

Reputation: 3563

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.

Upvotes: 2

Related Questions