title: byte[] to XML with .NET/C#
body: <p>I have XML stored in the database as a byte array (byte[]). Now I need to get that byte array from the database which I'm successfully doing and pass it to XDocument like the following:</p>
  
  <pre><code>public Dictionary&lt;string, string&gt; ReadFromByte(byte[] UserData, string toplevelnode, string firstattribute, string secondattribute)
          {
              XDocument doc = XDocument.Load(UserData);
              Dictionary&lt;string, string&gt; dictionary = doc.Descendants(toplevelnode).ToDictionary(x =&gt; x.Attribute(firstattribute).Value,
                                                                 x =&gt; x.Attribute(secondattribute).Value);
              return dictionary;
          }
  </code></pre>
  
  <p>This code works fine if I pass to XDocument a file on the server in XML format. However it doesn't work if I pass a byte[] array. </p>
  
  <p>Any hint how I should conert byte[] array back to XML would be greatly appreciated.</p>
  
  <p>Thanks.</p>