您好我有这个代码可以在我的解决方案中从项目中加载一个dll。 Dll现在处于另一种解决方案中。
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());
}
Dll实现了与ICalculationExpert
完全相同的界面。实际上我将界面复制到了其他解决方案。所以我知道演员应该工作,因为它是一个实现相同接口的对象。
事情就是它抛出了无效的施法异常。
我的猜测是另一个命名空间中的界面搞砸了演员表。
另一个解决方案中CalculationExpert
和ICalculationExpert
位于namespace Expert
。我的解决方案中的ICalculationExpert
位于namespace GSoft.Sons.Bll.ScoreExpert
我能读到的任何想法或资源吗?
答案 0 :(得分:0)
通过OOP原则将接口复制到您的解决方案并不会使它完全相同。如果您有权访问dll(带有ICalculationExpert接口的名称空间专家),为什么不在解决方案中添加dll引用,您可以通过该引用从名称空间专家实现相同的接口。