typeemismatchexception:不能转换字典类型的属性值

本文关键字:属性 类型 字典 不能 转换 typeemismatchexception | 更新日期: 2023-09-27 18:19:16

我正在努力解决一个问题,非常感谢您的帮助。

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; }
}

都是命名空间解决方案的一部分。

在春天

。网络配置:

<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。typeemismatchexception:无法转换类型[System. collections . generic . dictionary ' 2] [System. collections . generic . dictionary]的属性值。String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[解决方案。]求解器,解,Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]到所需类型[System. collections . generic . dictionary ' 2] [[System. collections . generic . dictionary ' 2]。String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[solution. isolver ' 1] [[solution. ini]]IEntity, solution, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], solution, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]],用于属性" Solvers " .

typeemismatchexception:不能转换字典类型的属性值

<objects xmlns="http://www.springframework.net">
  <object id="Client" type="solution.Client, solution">
    <property name="Solvers">
      <dictionary key-type="string" value-type="solution.ISolver&lt;solution.IEntity&gt;, solution">
        <entry key="SolverMp" value-ref="SolverMp"></entry>
      </dictionary>
    </property>
  </object>
</objects>

配置中至少有一个问题:

value-type="solution.Solver

求解器字典的值类型是

ISolver<IEntity>>