title: "Namespace prefix not defined" when it actually is defined
body: <p>I'm having trouble deserializing XML with an "undefined" namespace prefix which really is defined.</p>
  
  <p>We've published an internal web service in C# which serves a variety of clients.  A new client's IDE insists on declaring xsi:type for every element in its XML output, and they can't turn off this "feature".</p>
  
  <p>The XML message they produce goes like this, where "namespace" is the correct namespace.</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;soapenv:Body&gt;
    &lt;myOperation xsi:type="ns1:namespace" xmlns="namespace" xmlns:ns1="namespace"&gt;
      &lt;inputString xsi:type="xsd:string"&gt;ABCDEF&lt;/inputString&gt;
      &lt;books xsi:type="ns1:booksType"&gt;
        &lt;bookID xsi:type="xsd:string"&gt;ABC123&lt;/bookID&gt;
        &lt;bookID xsi:type="xsd:string"&gt;DEF456&lt;/bookID&gt;
      &lt;/books&gt;
      &lt;!-- ... snip... --&gt;
    &lt;/myOperation&gt;
  &lt;/soapenv:Body&gt;
  </code></pre>
  
  <p><code>&lt;books&gt;</code> is basically an array of strings.</p>
  
  <p>The service method accepts  as XmlNode, but XmlSerializer throws a "prefix 'ns1' not defined" error.  (It is defined in a parent node, but apparently that is not good enough.)  I have a similar problem using wsdl.exe to generate classes and deserialize the input for me.</p>
  
  <p>Using XmlNamespaceManager to specify prefixes doesn't seem right -- akin to magic numbers, and I can't predict which prefix a given consumer will declare anyway.  Is there a way to handle this without stripping the attributes out (books.Attributes.RemoveAll)?  That doesn't feel particularly elegant either.</p>
  
  <p>I've found that books.OuterXML does not contain any information for 'ns1' unless I hack the element inbound to use that prefix (), so I can see why it complains, but I don't yet understand why 'ns1' isn't recognized from its previous definition above.</p>
  
  <p>Many thanks for any help, or at least education, someone can provide.</p>
  
  <p>Edits: it works fine if I change <code>&lt;books&gt;</code> to use the prefix, i.e. <code>&lt;ns1:books xsi:type="ns1:booksType"&gt;</code>.  This works whether I've defined xmlns or no.  That may be consistent with <a href="https://stackoverflow.com/questions/2141181/xml-a-namespace-prefix-is-claimed-to-be-not-declared-when-it-fact-it-is">this answer</a>, but I still don't see how I would feasibly declare the prefix in the service code.</p>
  
  <p>@Chris, certainly.  Hope I can strike a balance between "stingy with closed source" and "usable for those who would help".  Here "books" is the XmlNode received in the service method parameter.  (Not to get off topic, but will also humbly take suggestions to improve it in general; I'm still a novice.)</p>
  
  <pre><code>XmlSerializer xmlSerializer = new XmlSerializer(typeof(booksType));
  StringReader xmlDataReader = new StringReader(books.OuterXml);
  books = (booksType)xmlSerializer.Deserialize(xmlDataReader);
  </code></pre>
  
  <p>The class is pretty much this:</p>
  
  <pre><code>[Serializable()]
  [XmlRoot("books", Namespace = "namespace")]
  [XmlTypeAttribute(TypeName = "booksType", Namespace = "namespace")]
  public class booksType
  {
      [XmlElement(ElementName = "bookID")]
      public string[] bookIDs { get; set; }
  }
  </code></pre>