- Notifications
You must be signed in to change notification settings - Fork752
Closed
Labels
Milestone
Description
Environment
- Pythonnet version: 2.3.0
- Python version: 3.6 (Anaconda 32-bit)
- Operating System: Windows 10
Details
I have the following code:
Interface1.cs
usingSystem.Collections.Generic;publicinterfaceInterface1{stringTest();List<string>GetList();List<MyType>GetListOfMyType();}publicclassMyType{}
Class1.cs
usingSystem.Collections.Generic;namespacePython.EmbeddingTest{publicclassClass1:Interface1{publicstringTest(){return"test";}publicList<string>GetList(){returnnewList<string>(){"testing"};}publicList<MyType>GetListOfMyType(){returnnewList<MyType>(){newMyType(),newMyType()};}}}
Module1.py
importclrclr.AddReference("Python.EmbeddingTest")fromPython.EmbeddingTestimport*classClass2(Class1):defTest(self):return"Test from Class2"defMethod1(self):return"Method1"
Test
I am trying to do something like what the following test is trying to do:
[Test]publicvoidTestGenericListMarshalling(){varscope=Py.Import("module1");varattr=scope.GetAttr("Class2");dynamicc2=attr.Invoke();List<string>ls=c2.GetList();}
Exception
However, I get the following exception:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException occurred HResult=0x80131500 Message=Cannot implicitly convert type 'Python.Runtime.PyObject' to 'System.Collections.Generic.List<string>' Source=Python.EmbeddingTest StackTrace: at Python.EmbeddingTest.PyImportTest.TestGenericListMarshalling() in D:\Users\Tom\Dropbox\Algo Trading\pythonnet\src\embed_tests\pyimport.cs:line 90
Is it possible to marshall generic .NET Lists?