Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheritance not working with non-abstract base methods #755

Closed
bminixhofer opened this issue Oct 21, 2018 · 2 comments
Closed

Inheritance not working with non-abstract base methods #755

bminixhofer opened this issue Oct 21, 2018 · 2 comments

Comments

@bminixhofer
Copy link

bminixhofer commented Oct 21, 2018

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.6.3
  • Operating System: Windows 10

Details

  • Describe what you were trying to get done.

This issue comes from this StackOverflow question.
I was trying to use a C# DLL which has a class that overrides a non-abstract method of its parent class. Although the new method should be used, pythonnet still calls the parent method. The code for a minimal DLL to reproduce this problem looks like this:

using System;

namespace InheritanceTest
{
    public class BaseClass
    {
        public bool Transmit()
        {
            throw new NotImplementedException();
        }
    }

    public class InheritedClass: BaseClass
    {
        public new bool Transmit()
        {
            Console.WriteLine("Success!");
            return true;
        }
    }
}

In the following python code, BaseClass.Transmit should be called when BaseClass is directly instantiated and InheritedClass.Transmit when InheritedClass is instantiated. However, BaseClass.Transmit is called both times.

## setup
import clr
import os

clr.AddReference(os.getcwd() + '\\InheritanceTest.dll')
import InheritanceTest

## method test

base_class = InheritanceTest.BaseClass()
base_class.Transmit() # throws a NotImplementedException as expected

inherited_class = InheritanceTest.InheritedClass()
inherited_class.Transmit() # still throws a NotImplementedException, although it should call InheritedClass.Transmit
@den-run-ai
Copy link
Contributor

@bminixhofer related #552?

@bminixhofer
Copy link
Author

@denfromufa It seems to me that #552 is the exact same issue (although worded a little strangely in my opinion, i wasn't able to find it when first researching the problem).
#756 fixes #552 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants