Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RuntimeBinderException - Cannot implicitly convert type 'Python.Runtime.PyObject' to 'System.Collections.Generic.List<string>' #451

Closed
Milestone
@tomhunter-gh

Description

@tomhunter-gh

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp