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

Exception when deriving from a .NET class with abstract methods in Python #2571

Open
@Eswcvlad

Description

@Eswcvlad

Environment

  • Python.NET version: 3.0.5
  • Tested on three configurations:
    • Windows 10, Python 3.12.4, .NET Framework
    • Windows 10, Python 3.12.4, .NET 9.0.201
    • Debian 12, Python 3.11.2, .NET 8.0.407

Details

I have an abstract .NET class, which has abstract methods to override within anetstandard2.0 library. When I try to derive from such a class in Python, it throws aTypeError during class object creation.

Below is a basic example.

.NET library code:

namespaceTestLib{publicabstractclassTestClass{publicstringFoo(){return"Foo";}protectedabstractstringBar();}}

Python code:

frompathlibimportPathimportclrclr.AddReference(str(Path(__file__).parent/'TestLib.dll'))fromTestLibimportTestClassclassSubTestClass(TestClass):__namespace__='CrlTest'defBar(self):return'Bar'if__name__=='__main__':stc=SubTestClass()print('Foo() -> '+stc.Foo())print('Bar() -> '+stc.Bar())

Python script output:

Traceback (most recent call last):  File "<redacted>\crl_test.py", line 10, in <module>    class SubTestClass(TestClass):TypeError: Method 'Bar' in type 'CrlTest.SubTestClass' from assembly 'Python.Runtime.Dynamic, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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