Uploaded image for project: 'Spring.NET'
  1. Spring.NET
  2. SPRNET-1470

Setting property of type IList<T> using <list/> without the @element-type specified fails.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3.2
    • Fix Version/s: 2.0 M1
    • Component/s: Spring-NET-CORE
    • Labels:
      None

      Description

      If I try to set a property of type IList<T> using the <list> without the element-type attribute, the object factory fails with a TypeMismatchedException. That is, if my target class has a property like so

      public IList<string> GenericStringIList

      { get; set; }

      And I try to set it in my spring config with the following xml fragment

      <property name="GenericStringIList">
      <list>
      <value>string1</value>
      </list>
      </property>

      It fails with
      [Spring.Core.TypeMismatchException: Cannot convert property value of type [System.Collections.ArrayList] to required type [System.Collections.Generic.IList`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]] for property 'GenericStringList'., Inner Exception: Spring.Core.TypeMismatchException: Cannot convert property value of type [System.Collections.ArrayList] to required type [System.Collections.Generic.IList`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]] for property 'GenericStringList'.
      at Spring.Core.TypeConversion.TypeConversionUtils.ConvertValueIfNecessary(Type requiredType, Object newValue, String propertyName) in C:\work\spring-net\src\Spring\Spring.Core\Core\TypeConversion\TypeConversionUtils.cs:line 215]

      What is strange about this is that if the property is declared as a regular List<>, everything is fine.

      public List<string> GenericStringIList { get; set; }

      An even more minimal test like the following shows the problem more clearly

      [Test]
      public void ConvertArrayListToGenericIList() {
      var xs = new ArrayList

      { "Mark Pollack" }

      ;
      var ys = TypeConversionUtils.ConvertValueIfNecessary(typeof(IList<string>), xs, "ignored");
      Assert.That(ys as IList<string>, Is.Not.Null);
      var zs = (IList<string>)ys;
      Assert.That(zs[0], Is.EqualTo("Mark Pollack"));
      }

      This also bombs for the same reason.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sbohlen Steve Bohlen
                Reporter:
                choy.rim Choy Rim
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: