Accessing C# DLL through Python 3.8 using Python.Net (TypeError)

Question:

I have the following python 3.8.2 code that attempts to access methods from my C# DLL
In the example it is using a method to calculate the area of a pipe.

import clr

clr.AddReference(r"calcsDLL")
from myDLL import calcs

calcs.Pipe_Area(0.2)

Here is my implementation of the C# DLL

namespace myDLL
{
    public class calcs
    {
        public double pipe_area(double pipeDiameter)
        {
         double pipeArea = 0.25 * 3.1415 * Math.Pow(pipeDiameter, 2);
         return pipeArea;
        }
    }
}

Most frustrating of all is that I had this exact code working already, I changed the DLL build inside Visual Studio to Any CPU to see if it would break the connection (it broke something) however when I changed it back to x64 build the python script was still broken. The python script still can connect and see the DLL methods however throws a type error when I try to execute them.

The error message I get from Python is:

TypeError: No method matches given arguments for Pipe_Area: ()

Asked By: Eog

||

Answers:

Solution: The classes must be static as I’m not creating a new instance within the python script.

Answered By: Eog