Inheritance not working with non-abstract base methods
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; } } }
- 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.
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