我正在努力解决问题,非常感谢一些帮助 .
public interface ISolver<T>
{
void Solve();
}
public class Solver : ISolve<IEntity>
{
void Solve()
{
...code that solves the given problem
}
}
public class Client : IClient<IEntity>
{
public Dictionary<string, ISolver<IEntity>> Solvers { get; set; }
}
All are part of namespace solution.
在Spring.Net配置中:
<object id="Client" type="solution.Client, solution">
<property name="Solvers">
<dictionary key-type="string" value-type="solution.Solver, solution">
<entry key="SolverMp" value-ref="SolverMp"></entry>
</dictionary>
</property>
</object>
<object id="SolverMp" type="solution.Solver, solution">
</object>
我得到了例外:
Spring.Core.TypeMismatchException:无法转换类型的属性值[System.Collections.Generic.Dictionary
2 [[System.String,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089],[solution.Solver] ,solution,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]]到必需的类型[System.Collections.Generic.Dictionary
2 [[System.String,mscorlib,Version = 4.0.0.0,Culture = neutral, PublicKeyToken = b77a5c561934e089],[solution.ISolver`1 [[solution.IEntity,solution,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]],solution,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null ]]]属性'Solvers' .
2 回答
至少有一个问题是您的配置中的此条目:
Solvers字典的值类型是
这就是异常所抱怨的 .