Hello I have this code that worked to load a dll from a project in my solution. The Dll is now in another solution.
public void LoadCalculationExpert(string pathToExpert)
{
var assembly = Assembly.LoadFrom(pathToExpert);
var type = assembly.GetType("Expert.CalculationExpert");
var calculationExpert = (ICalculationExpert)Activator.CreateInstance(type);
this._container.RegisterInstance(calculationExpert, new ContainerControlledLifetimeManager());
}
The Dll implement an interface perfectly identical to ICalculationExpert. In fact I copied interface to the other solution. So I know that the cast should work because it is an object that implement the same interface.
The thing is it throws me invalid cast exception.
My guess is the interface being in another namespace screw the cast.
The CalculationExpert and ICalculationExpert is in namespace Expert in another solution. ICalculationExpert in my solution is in namespace GSoft.Sons.Bll.ScoreExpert
Any idea or resource I could read ?
By OOP principles copying the interface over to your solution is not going to make it identical. If you have access to the dll (namespace Expert with ICalculationExpert interface) why not add dll reference in your solution by which you can implement the same interface from namespace Expert.