title: There is an error in XML document (1, 1). while deserializing
body: <p>I am using <strong>Silverlight</strong> for my serializing and deserializing.</p>
  
  <p>I ahve succesfully done serializing by obtaining objects from the class and the xml which i obtained on serializing , the <strong>same xml</strong> i am trying to deserialize.</p>
  
  <p>My code to do so is:</p>
  
  <pre><code>namespace SliderLastTry
  {
      public class ControlClass
      {
          public void Main()
          {
  
              Parameters pc = new Parameters()
                {
                    Parameter = { new Parameter { Name = "Name1", Label = "Label1", Unit = "Uint1", Component = { new Component { Type = "Type1", Attributes = { new Attributes { Type = "Combo", Displayed = "42", Selected = "02", Items = { "10", "11", "12", "13", "14" } } } } } }, { new Parameter { Name = "Name2", Label = "Label2", Unit = "Uint2", Component = { new Component { Type = "Type2", Attributes = { new Attributes { Type = "Slider", Displayed = "52", Selected = "05", Items = { "20", "21", "22", "23", "24" } } } } } } } }
                 ,
                    Separator = { new Separator { Separators = "AutoSkew1" } }
                };
              String xml = pc.ToXml(); //This function serializes and returns xml.
              XmlSerializer deserializer = new XmlSerializer(typeof(Parameters));
              XmlReader reader = XmlReader.Create(new StringReader(xml));
              Parameters parameter = (Parameters)deserializer.Deserialize(reader);
          }
      }
  </code></pre>
  
  <p><strong>This line in this code gives me exception:</strong></p>
  
  <pre><code>Parameters parameter = (Parameters)deserializer.Deserialize(reader);
  </code></pre>
  
  <p>Thsi is code for serializing (I mean the class where MyXML is defined):</p>
  
  <pre><code>namespace SliderLastTry
  {
      public static class Xml
      {
          public static string ToXml(this object objectToSerialize)
          {
               var memory = new MemoryStream();
               var serial = new XmlSerializer(objectToSerialize.GetType());
               serial.Serialize(memory, objectToSerialize);  
              var utf8 = new UTF8Encoding();
              return utf8.GetString(memory.GetBuffer(), 0, (int)memory.Length);  
          }
      }
  }
  </code></pre>
  
  <p>And the warning obtained is:</p>
  
  <pre><code>There is an error in XML document (1, 1).
  </code></pre>
  
  <p>Please see the exception in details:</p>
  
  <p>Inner Exception: </p>
  
  <pre><code> {System.Xml.XmlException: Invalid data at root level. Line 1, position 1. 
          to System.Xml.XmlTextReaderImpl.Throw (Exception e) 
          to System.Xml.XmlTextReaderImpl.Throw (String res, String arg) 
          System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace to () 
          System.Xml.XmlTextReaderImpl.ParseDocumentContent to () 
          System.Xml.XmlTextReaderImpl.Read to () 
          System.Xml.XmlReader.MoveToContent to () 
          Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderParameters.Read7_parameters to ()}
  </code></pre>
  
  <p>At stack Trace:</p>
  
  <pre><code>at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader, String encodingStyle, Object events)
  at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader, String encodingStyle)
  at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader)
  SliderLastTry.ControlClass.Main to ()
  ctor to SliderLastTry.MainPage .. ()
  at SliderLastTry.App.Application_Startup (Object sender, e StartupEventArgs)
  at MS.Internal.CoreInvokeHandler.InvokeEventHandler (UInt32 indexType, handlerDelegate Delegate, Object sender, Object args)
  at MS.Internal.JoltHelper.FireEvent (unmanagedObj IntPtr, IntPtr unmanagedObjArgs, argsTypeIndex Int32, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)
  </code></pre>