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

ValidationErrors ReadXml serialization bug

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.3.1
    • Fix Version/s: 1.3.2
    • Component/s: None
    • Environment:
      net-4.0

      Description

      ValidationErrors and ErrorMessage serialization from XML is incorrect. Both ValidationErrors.ReadXml and ErrorMessage.ReadXml do not corretly read the serialized XML in all scenarios: 1, 2 or mor providers; 1, 2 or more errors per provider; 0, 1, 2 or more parameters per error.

      This code in ValidationErrors solves the problem:

      /// <summary>
      /// Generates an object from its XML representation.
      /// </summary>
      /// <param name="reader">
      /// The <see cref="T:System.Xml.XmlReader"></see> stream
      /// from which the object is deserialized.
      /// </param>
      public void ReadXml(XmlReader reader)
      {
      if (!reader.IsEmptyElement)
      {
      reader.Read();
      while (reader.Name == "Provider")
      {
      object key = reader.GetAttribute("Id");
      reader.Read();
      while (reader.Name == "ErrorMessage")
      {
      //XmlSerializer xs = new XmlSerializer(typeof(ErrorMessage));
      //object value = xs.Deserialize(reader);
      object value = ReadErrorMessage(reader);

      IList mapValue = (IList)errorMap[key];

      if (mapValue == null)

      { mapValue = new ArrayList(); errorMap[key] = mapValue; }

      mapValue.Add(value);
      reader.Read(); //<ErrorMessage> o </Provider>
      }
      reader.Read();
      }
      }
      }

      private ErrorMessage ReadErrorMessage(XmlReader reader)
      {
      object parameters = null;
      string id = reader.GetAttribute("Id");
      if (!reader.IsEmptyElement)
      {
      reader.Read(); //<Parameters> o </ErrorMessage>
      if (reader.Name == "Parameters")
      {
      reader.Read(); //<ArrayOfAnyType> o </Parameters>
      if (reader.Name == "ArrayOfAnyType")

      { XmlSerializer xs = new XmlSerializer(typeof(object[])); parameters = (object[])xs.Deserialize(reader); }

      reader.Read(); //</ErrorMessage>
      }
      }
      return new ErrorMessage(id, parameters);
      }

        Attachments

          Activity

            People

            Assignee:
            sbohlen Steve Bohlen
            Reporter:
            bocca Bocca Romel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: