Pythonnet function call to c# method with 2d List parameter fails

C# class

using System.Collections.Generic;
namespace List2dEx
{
    public class Test2dList
    {
        public int MatrixTest(IList<IList<double>> matrix)
        {
            return matrix.Count;
        }
        public int VectorTest(IList<double> vector)
        {
            return vector.Count;
        }
    }
}

Python

import clr
clr.AddReference(r"D:\testwork\List2dEx\bin\Debug\List2dEx.dll")

import List2dEx
from System.Collections.Generic import List
from System import Double
from List2dEx import Test2dList

test = Test2dList()

val = List[Double]()
val.Add(1.1)
val.Add(1.1)
val.Add(1.1)
ret = test.VectorTest(val)
print(ret)

valList = List[List[Double]]()
valList.Add(val)
ret = test.MatrixTest(valList)
print(ret)

List i.e method VectorTest works perfectly fine, but 2d list i.e method MatrixTest gives the error “No method matches given arguments for MatrixTest: (<class System.Collections.Generic.List[List[Double]]'>)”
When the Method signature is changed to List “public int MatrixTest(List<List> matrix)” then it works, but method signature cannot be changed.

Welcome to Python Discussions. Thanks for fixing the formatting.
Please let us know if the pop-up “Are you posting code?” did not show for you.

Old request to fix the formatting (kept collapsed for reference)

I am wondering if you noticed that this forum uses Markdown for post formatting. When you paste a program code directly into a post it will be almost certainly mangled by the Markdown formatting. You can probably see that the code in your post is mangled into an invalid code.

Did the following pop-up show for you when you were posting the message? The pop-up was enabled here recently.

https://aws1.discourse-cdn.com/business6/uploads/python1/original/2X/0/009304213fa6333c321fe6d7a522b2ea2fe8106b.jpeg

Information for new users - #30 by ambv

Please edit your post to enclose your code snippets between lines with triple backticks as instructed in the pop-up.


Note that it is possible that in this forum there are not many users having enough experience with pythonnet / Python.NET.

You can check the chat and the mailing list of the project:

https://mail.python.org/mailman3/lists/pythonnet.python.org/