I have a strange problem in my project. I have a class that inherits from a base class (which again inherits from another base class) and overrides a function. However, when that function is called it never calls the overridden function, but the base function.
However, when I override that function in the middle class it is called. But this is confusing: let's explain with a drawing :)
lib GuiShared
- class bScreen
- virtual function InitializeRoc
- class bScreen
lib TigerControlRoot
- class bTigerScreen
- override function InitializeRoc <-- when overriden here it gets called
- class bTigerScreen
- lib TigerControlRootCommonScreens
- class CheckInRules
- override function InitializeRoc <-- not called :s
- class CheckInRules
The constructor gets called however...
Here's my (simplified) code:
The shared base class
namespace Ppb.GuiShared.Screens {
public partial class bScreen<T> : Ppb.Controls.pPanel where T : FrameworkMiddleware.Framework.Remoting.Remotable, FrameworkMiddleware.IInitialize, new() {
public virtual void Load(bMain<T>.LoadEventArgs args) {
log.Trace("InitializeRoc " + this.GetType().FullName);
InitializeRoc(args);
_hasLoaded = true;
}
protected virtual void InitializeRoc(bMain<T>.LoadEventArgs args) { }
}
}
project base class
namespace Tiger.ControlRoot.Screens {
public partial class bTigerScreen : Ppb.GuiShared.Screens.bScreen<roc.Tiger> {
public bTigerScreen(GuiSettings settings, roc.Tiger tiger)
: base(settings, tiger) {
InitializeComponent();
InitializeMenu();
}
}
}
The failing class (or any other class from that lib)
namespace Tiger.ControlRoot.CommonScreens {
[ControlRoot.Screens.TigerScreenInfo("Testje", Tiger.ControlRoot.Screens.TigerScreenInfoAttribute.elevel.User, true)]
public class CheckInRules : ControlRoot.Screens.bTigerScreen {
public CheckInRules(GuiSettings settings, roc.Tiger tiger)
: base(settings, tiger) {
}
protected override void InitializeRoc(Ppb.GuiShared.bMain<TigerMiddleware.TigerRoc.Tiger>.LoadEventArgs args) {
base.InitializeRoc(args);
}
}
}
And if that wasn't enough, when I try to call some function on the base class I receive a TypeLoadException.
GenericArguments[0], 'TigerMiddleware.TigerRoc.Tiger', on 'Ppb.GuiShared.bMain`1+LoadEventArgs[T]' violates the constraint of type parameter 'T'.
Similar code with the same GuiShared lib is used in another project and there there are no issues.