title: C# Xml Serialize Attribute Adding Custom Namespace
body: <p>I am trying to add namespace during Xml Serialization. So far I have added some of them but I am unable to add custom namespace using Xml serializer.</p>
  
  <p>So far I have achieved this </p>
  
  <pre><code>   &lt;?xml version="1.0"?&gt;
  &lt;manifest xmlns:xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2e" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" xsi:schemaLocation="http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xs" identifier="test" version="2"&gt;
    &lt;lom xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test lom" xmlns="http://ltsc.ieee.org/xsd/LOM" /&gt;
    &lt;resource adlcp:scormtype="sco" /&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>This is my Code</p>
  
  <p>Manifest Class</p>
  
  <pre><code>[Serializable]
  [XmlRoot(ElementName = "manifest")]
  public class Manifest
  {
      /// &lt;summary&gt;
      /// manifest root node
      /// &lt;/summary&gt;
      [XmlAttribute(AttributeName = "identifier")]
      public string Identifier { get; set; }
  
      [XmlAttribute(AttributeName = "version")]
      public string Version { get; set; }
  
      //[XmlAttribute(AttributeName = "adlcp", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
      //public string Adlcp = "http://www.adlnet.org/xsd/adlcp_rootv1p2";
  
      [XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
      public string SchemaLocation = "http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xs";
  
  
      [XmlElement(ElementName = "lom", Namespace = "http://ltsc.ieee.org/xsd/LOM")]
      public Lom Lom { get; set; }
  
      [XmlElement("resource")]
      public Resource Resource { get; set; }
  }
  </code></pre>
  
  <p>Lom Class</p>
  
  <pre><code> public class Lom
      {
          [XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
          public string SchemaLocation { get; set; }
  
          [XmlAttribute(AttributeName = "xsi", Namespace = "http://www.imsproject.org/xsd/imscp_rootv1p1p2e")]
          public string Xsi = "http://www.w3.org/2001/XMLSchema-instance";
  
  
      }
  </code></pre>
  
  <p>Resource Class</p>
  
  <pre><code> public class Resource
      {
          [XmlAttribute(AttributeName = "scormtype", Namespace = "http://www.adlnet.org/xsd/adlcp_rootv1p2")]
          public string ScormType { get; set; }
      }
  </code></pre>
  
  <p>My serialization function like this</p>
  
  <pre><code>using (FileStream fs = new FileStream(filePath, FileMode.Create))
          {
              var xmlSerializer = new XmlSerializer(typeof(Manifest));
  
          var ns = new XmlSerializerNamespaces();
          ns.Add("xmlns", "http://www.imsproject.org/xsd/imscp_rootv1p1p2e");
          ns.Add("adlcp", "http://www.adlnet.org/xsd/adlcp_rootv1p2");
          ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
          xmlSerializer.Serialize(fs, data, ns);
  
          fs.Close();
  
      }
  </code></pre>
  
  <p>I need output like this.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
      &lt;manifest 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      identifier="test" version="2" 
      xmlns:adlcp="test"
      xsi:schemaLocation="test location" 
      **xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2"**&gt;
        &lt;lom 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM lom.xsd" 
        xmlns="http://ltsc.ieee.org/xsd/LOM" /&gt;
       &lt;resource adlcp:scormtype="sco"/&gt;
      &lt;/manifest&gt;
  </code></pre>
  
  <p>what I am doing wrong?</p>