C# .net Deserialization I get an exception.

Posted by starz26 on Stack Overflow See other posts from Stack Overflow or by starz26
Published on 2010-05-21T10:40:22Z Indexed on 2010/05/21 10:50 UTC
Read the original article Hit count: 378

Filed under:
|
|
namespace N1
{
    public class InputEntry
    {  
    //FieldName is a class tht is generated from an XSD which has complex type Name and value
        private FieldName[] name;
        public FieldName[] Name
        {
            get { return this.Name; }
            set { this.Name = value; }
        }
    }

    public class B
    {
        public void Method1()
        {
            InputEntry inputEntry = new InputEntry();
            inputEntry.Name = "abc";
        }

        private void Method2(InputEntry inputEntry)
        {
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(InputEntry));
            System.IO.StringWriter inputStr = new System.IO.StringWriter(CultureInfo.InvariantCulture);
            serializer.Serialize(inputStr, inputEntry);
            string ipEntry = inputStr.ToString();
            Method3(ipEntry);
        }

        private void Method3(string ipEntry)
        {
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(InputEntry));
            System.IO.StringReader inputStr = new System.IO.StringReader(ipEntry);
            InputEntry inputEntry = (InputEntry)serializer.Deserialize(inputStr);

        }
    }
}

I get an exception when deserialising the follwing data(when a client configues data as <FieldName>PRINTLINE00</FieldName> <FieldValue>DENIAL STATE</FieldValue> )

Exception is:

Message: There is an error in XML document (6, 22).

String:

<?xml version="1.0" encoding="utf-16"?>
<InputEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <Fields>
    <Field>
      <FieldName>PRINTLINE00</FieldName>
      <FieldValue>&#x1B;DENIAL STATE 217</FieldValue>
      </Field>
</InputEntry>

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET