When I use reflection in this case, the created type can be many generic types.
BaseStepHandler<BaseStepDataModel> activator = (BaseStepHandler<BaseStepDataModel>)Activator.CreateInstance(....);
The created instance can be all childs of BaseStepDataModel.
BaseStepHandler<OneDataModel>
OR
BaseStepHandler<TwoDataModel>
OneDataModel and TwoDataModel are extending BaseStepDataModel.
this is the exception that I get:
Unable to cast object of type '....GlobalOnBoardingStepOneHandler' to type '....BaseStepHandler`1[....BaseStepDataModel]'.
this is the declaration if GlobalOnBoardingStepOneHandler.
public class GlobalOnBoardingStepOneHandler : BaseStepHandler<GlobalOnBoardingStepOneDataModel>{}
See Question&Answers more detail:os