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

Passing Python objects implementing a generic C# interface to a C# method fails in 3.0.0 #1982

Closed
@fractus

Description

@fractus

Environment

  • Pythonnet version: 2.5.2 and 3.0.0.post01
  • Python version: 3.7.6 (2.5.2) and 3.9.12 (3.0.0.post01)
  • Operating System: Win10
  • .NET Runtime: .NET 6

Details

Passing a Python object (obj) that implements a generic interface in Python (ISome) to a C# classfails in pythonnet 3.0 butworks in 2.5.2; same behaviour whether specific (SomeSpecific) or generic (SomeGeneric)

namespaceSome.Namespace{publicinterfaceISome<T1>{publicT1Get1(T1x);}publicclassSomeSpecific{publicSomeSpecific(ISome<int>some,intx){Console.Out.WriteLine($"Spec1 ={some.Get1(x)}");}}publicclassSomeGeneric<T1>{publicSomeGeneric(ISome<T1>some,T1x){Console.Out.WriteLine($"Gen1 ={some.Get1(x)}");}}}
fromSome.NamespaceimportISome,SomeGeneric,SomeSpecificclassPySome(ISome[int]):__namespace__='Some.Namespace'defGet1(self,x):returnxobj=PySome()print(obj.Get1(4))# Next two lines fail in 3.0.0SomeSpecific(obj,4)SomeGeneric[int](obj,4)
  • If there was a crash, please include the traceback here.
Traceback (mostrecentcalllast):SomeSpecific(obj,4)System.ArgumentException:CannotresolvemethodInt32Get1(Int32)becausethedeclaring typeofthemethodhandleSome.Namespace.ISome`1[T1]isgeneric.Explicitlyprovidethedeclaring typetoGetMethodFromHandle.atSystem.Reflection.MethodBase.GetMethodFromHandle(RuntimeMethodHandlehandle)atPython.Runtime.PythonDerivedType.MarshalByRefsBack(Object[]args,RuntimeMethodHandlemethodHandle,PyObjectpyResult,Int32outsOffset)in/tmp/build-via-sdist-rlpexh5w/pythonnet-3.0.0.post1/src/runtime/Types/ClassDerived.cs:line844atPython.Runtime.PythonDerivedType.InvokeMethod[T](IPythonDerivedTypeobj,StringmethodName,StringorigMethodName,Object[]args,RuntimeMethodHandlemethodHandle)in/tmp/build-via-sdist-rlpexh5w/pythonnet-3.0.0.post1/src/runtime/Types/ClassDerived.cs:line727atSome.Namespace.PySome.Get1(Int32 )atSome.Namespace.SomeSpecific..ctor(ISome`1some,Int32x)in

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp