How do you expect him to be connected? The compiler associates the call to this.Generate(item) with the only possible candidate: Generator.Generate(DerivedA a) . This has nothing to do with when the binding occurs; DerivedGenerator.Generate(DerivedB b) not considered a valid candidate because Generator has absolutely no idea about its existence, and you call the method through a statically typed instance of Generator this (I note that the protected method is not a question, even if it was public , the second call failed). Why should the base class know anything about the new virtual method defined in the derived class?
To do this, you either define virtual Generate(DerivedB) in the Generator base class, or override it in DerivedGenerator , or if this is not an option, you make everything resolved at runtime.
In your case, as Brian correctly points out, you will need to make an instance of the Generator dynamic to enable the binding of the Generate call to DerivedGenerator.Generate when it is approved. Otherwise, the selection of candidates will be limited only to those of which the Generator knows.
This obliges you to significantly rebuild your code, since you will also need to make Generate at least internal or internal protected .
In addition, I should note that making a dynamic.Generate(dynamic) call to create a job seems like a big smell to me, and you are probably abusing a system like C #. I would consider reorganizing your code into a more secure solution.
I also recommend that you read Eric Lippert's science fiction series: Wizards and warriors explaining how certain hierarchies of objects cannot be well expressed by the C # system and how you could (but usually shouldn't) use dynamic to achieve double sending to C # to get around some of its limitations.
source share