Type parameter works directly, but fails inside `List<>` · Issue #962 · pythonnet/pythonnet

Environment

  • Pythonnet version: 2.4.0
  • Python version: Python 3.7.4
  • Operating System: Windows 10 (18362.356)

Details

  • Describe what you were trying to get done.

Call a generic method taking a list parameter.

C# library:

using System.Collections.Generic;

namespace CSLib
{
    public static class CSLib
    {
        public static bool GetBool() =>
            true;

        public static void TestValue<T>(T t) {}

        public static List<bool> GetBoolList() =>
            new List<bool>() { true, false };

        public static void TestList<T>(List<T> list) {}

        public static void Test()
        {
            TestValue<bool>(GetBool());
            TestList<bool>(GetBoolList());
        }
    }
}

Python code:

from clr import AddReference
from pathlib import Path

AddReference(str(Path.cwd() / "cslib/bin/Debug/netstandard2.0/cslib.dll"))

from System import Boolean
from CSLib import CSLib

CSLib.TestValue[Boolean](CSLib.GetBool())
CSLib.TestList[Boolean](CSLib.GetBoolList())

It works fine when the type argument is used directly, but fails when it is inside List<>.

  • If there was a crash, please include the traceback here.
Traceback (most recent call last):
  File "a.py", line 11, in <module>
    CSLib.TestList[Boolean](CSLib.GetBoolList())
TypeError: No method matches given arguments for TestList