0
votes

I am struggling to solve a problem and would really appreciate some help.

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.

In Spring.Net configuration:

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

I get the exception:

Spring.Core.TypeMismatchException: Cannot convert property value of type [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]]] to required type [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]]] for property 'Solvers'.

2
I assume you mean Solver : ISolver<IEntity> at the top and that it's a typoannonymously

2 Answers

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

At least one issue is this entry in your config:

value-type="solution.Solver

The value type of the Solvers dictionary is

ISolver<IEntity>>

And this is what the exception is complaining about.