question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot implement an interface that extends another interface

See original GitHub issue

Environment

  • Pythonnet version: 3.0.0a2
  • Python version: 3.8.10
  • Operating System: Ubuntu 20.04.4 LTS (docker run --rm -it ubuntu:20.04)
  • .NET Runtime: .NET Core 6.0.202

Details

  • Describe what you were trying to get done.

    Attempting to implement interfaces defined in .NET. Works fine for simple interfaces but I receive a weird error when the interface extends IDisposable

  • What commands did you run to trigger this issue? If you can provide a Minimal, Complete, and Verifiable example this will help us understand the issue.

from clr_loader import get_coreclr
rt = get_coreclr("conf.json")
from pythonnet import set_runtime
set_runtime(rt)
import clr

import System
import System.Buffers


class MyDisposable(System.IDisposable):
    __namespace__ = "MyNamespace"

    def Dispose(self) -> None:
        print("Dispose")

md = MyDisposable()
md.Dispose()


class MyBuffer(System.Buffers.IMemoryOwner):
    __namespace__ = "MyNamespace"


    def Dispose(self) -> None:
        print("Dispose")


mb = MyBuffer()
mb.Dispose()    

conf.json:

{
  "runtimeOptions": {
    "tfm": "net6.0",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "6.0.4"
    }
  }
}
  • If there was a crash, please include the traceback here.
(venv) root@ca20f043eef5:/t# python demo.py
Dispose
Traceback (most recent call last):
  File "demo.py", line 21, in <module>
    class MyBuffer(System.Buffers.IMemoryOwner):
TypeError: Method 'Dispose' in type 'MyNamespace.MyBuffer' from assembly 'Python.Runtime.Dynamic, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
phxnsharpcommented, May 6, 2022

The error has nothing specifically to do with IDisposable. Any interface that extends a second interface shows this problem:

>>> import clr
>>> import System.Collections
>>> class Bla(System.Collections.IDictionary):
...   __namespace__ = "MyNamespace"
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Method 'CopyTo' in type 'MyNamespace.Bla' from assembly 'Python.Runtime.Dynamic, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
0reactions
ari62commented, Feb 2, 2023

I’m seeing the same error with this for example:

from enum import Enum
class SourceKey(str, Enum):
    A = "a"
    B = "b"

cannot use multiple inheritance with managed classes
 During the algorithm initialization, the following exception has occurred: 
Loader.TryCreatePythonAlgorithm(): Unable to import python module /somemodule/somepython.py. 
AlgorithmPythonWrapper(): cannot use multiple inheritance with managed classes
  at <module>
Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Why an interface can not implement another interface?
Implements denotes defining an implementation for the methods of an interface. However interfaces have no implementation so that's not possible.
Read more >
Why an Interface Can Not Implement Another Interface
One interface can only extend other interface but cannot implement the other interface as interface can only have method declarations and not the...
Read more >
Can an interface implement another interface?
Yes. One interface can inherit another by use of the keyword extends. The syntax is the same as for inheriting classes. When a...
Read more >
Defining an Interface - The Java™ Tutorials
An interface can extend other interfaces, just as a class subclass or extend another class. However, whereas a class can extend only one...
Read more >
java - Why does an interface extend an interface instead of ...
Interface implementation implies a finality that cannot be created by another interface - by their nature, an interface is meant to be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found