views:

480

answers:

1

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
  • lib TigerControlRoot

    • class bTigerScreen
      • override function InitializeRoc <-- when overriden here it gets called
  • lib TigerControlRootCommonScreens
    • class CheckInRules
      • override function InitializeRoc <-- not called :s

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.

A: 

Okay, thanks for all (the) response(s), but I fixed it in the meantime.

The problem was the following: The failing class is in an dll from which its output path in debug mode is set to the executable's plugin folder. No problem so far, but it also copies its dependencies into that folder.
However, some of the dependencies are already copied to the executable's root folder. The executable when it startups searches all the plugins in the plugin folder and when required instantiates the plugin.
The problem then is that the plugin uses the dependencies from in the plugins folder while the executable uses the dependencies from the root folder which are basically the same file in a different dir, so while running the clr sees them as 2 different dll's and that really confuses the clr :).

So when the shared dependencies aren't copied to the plugins folder, everything runs fine because the plugins use the depedencies from the root folder and thus the same dll's.

Stormenet
You should probably accept your own answer, so that this no longer shows up as "unanswered".
oefe
@oefe I tried, but I had to wait 48 hours :)
Stormenet