Spring.Core.TypeMismatchException:无法转换Dictionary类型的属性值

时间:2012-01-01 22:38:55

标签: c# spring.net

我正在努力解决问题,并且非常感谢一些帮助。

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

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

在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],[解决方案] .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 =中性,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 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

配置中至少有一个问题:

value-type="solution.Solver

Solvers字典的值类型是

ISolver<IEntity>>

这就是异常所抱怨的。