title: type xxxx not expected use xmlinclude or soapinclude
body: <p>I have a curious case of this serialization issue - which has been asked many times on this site and I have gone through a few of these questions and tried the usual items to no avail:</p>
  
  <ul>
  <li>Add [XmlInclude] to the class throwing the error</li>
  <li>Remove namespaces</li>
  <li>Add a different namespace to each class</li>
  </ul>
  
  <p>To explain further, I have provided a simplified version of my code below. Essentially I am using a <code>WebServiceHost</code> object to run a RESTful service and one of my endpoints returns an object serialized as XML (I have annotated the object with <code>[DataContract]</code> and <code>[DataMember]</code> attributes). This object contains a <code>SerializableDictionary&lt;string, object&gt;</code> (<a href="https://stackoverflow.com/questions/67959/net-xml-serialization-gotchas">here</a>) where the value has been typed as <code>object</code>. I believe this is why it is failing:</p>
  
  <ul>
  <li>Works fine when the value is assigned a primitive</li>
  <li>When I assign a custom object to the KV pair V, I get the <em>unexpected type</em> exception probably because the Serializer does not know how to serilaize the object / some sort of namespacing issue</li>
  </ul>
  
  <p>Obviously, I am unable to annotate Object.cs with <code>[XmlInclude]</code> and because it is a service and I am not myself serializing I cannot using something like</p>
  
  <pre><code>new Serializer(typeof(...), new Type[] { ... }}
  </code></pre>
  
  <p>Any idea's of what I can do? I thought about not typing the dict value as object and rtaher comething more concrete but the problem is that this value can take primitives or cusotm types. Some code to explain the above:</p>
  
  <p><strong>Edit:</strong> Updated the code below to make it more clear</p>
  
  <pre><code>[DataContract]
  public class ResponseObject
  {
      [DataMember(Name = "data")]
      public SerializableDictionary&lt;string, object&gt; Data { get;set; }
  
      public ResponseObject()
      {
          Data = new SerializableDictionary&lt;string, object&gt;();
      }
  }
  
  ...
  
  var d1 = new ResponseObject();
  d1.Data.Add("some key", "some value"); //WORKS AND SERIALIZES PERFECLTY
  
  var d2 = new ResponseObject();
  d2.Data.Add("some other key", new SomeOtherObjecT());
  var d3 = new ResponseObject();
  d3.Data.Add("another key", d2);  //THIS THROWS THE UNEXPECTED TYPE ERROR WHEN SEIRLAIZING SomeOtherObject
  </code></pre>
  
  <p><strong>Edit:</strong> The error is thrown in SerializableDictionary where it is attempting to serialize an object of type ResponseObject. The two are in seperate projects - if that is significant?</p>