title: SOAP specified type was not recognized
body: <p>I'm trying to use a SOAP webservice with VS2013 + .net 4.5 but I'm getting the exception above calling the <code>getVechicles</code> method, I can't find the reason for this exception.</p>
  
  <p>Here is few things that I figured out:</p>
  
  <ul>
  <li>At the end of the exception I'm seeing a souspicious thing, the method <code>Read6_getVehiclesResponse</code> is calling the <code>Read3_Animal</code> method while it should try to read a <code>Vehicle</code>.</li>
  <li>If I remove the <code>Animal</code> and <code>Dog</code> types everything works fine.</li>
  </ul>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>System.ServiceModel.CommunicationException was unhandled
    HResult=-2146233087
    Message=Error in deserializing body of reply message for operation 'getVehicles'.
    Source=mscorlib
    StackTrace:
      Server stack trace: 
         at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
         at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
         at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
         at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
         at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc&amp; rpc)
         at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc&amp; rpc)
         at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
         at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
         at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
      Exception rethrown at [0]: 
         at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
         at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
         at WindowsFormsApplication4.ServiceReference.TestWebService.getVehicles(getVehicles request)
         at WindowsFormsApplication4.ServiceReference.TestWebServiceClient.WindowsFormsApplication4.ServiceReference.TestWebService.getVehicles(getVehicles request) in c:\Users\tiago\Documents\Visual Studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Service References\ServiceReference\Reference.cs:line 257
         at WindowsFormsApplication4.ServiceReference.TestWebServiceClient.getVehicles() in c:\Users\tiago\Documents\Visual Studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Service References\ServiceReference\Reference.cs:line 262
         at WindowsFormsApplication4.Form1.button1_Click(Object sender, EventArgs e) in c:\Users\tiago\Documents\Visual Studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Form1.cs:line 26
         at System.Windows.Forms.Control.OnClick(EventArgs e)
         at System.Windows.Forms.Button.OnClick(EventArgs e)
         at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
         at System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks)
         at System.Windows.Forms.Control.WndProc(Message&amp; m)
         at System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)
         at System.Windows.Forms.Button.WndProc(Message&amp; m)
         at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
         at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
         at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
         at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
         at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
         at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
         at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
         at System.Windows.Forms.Application.Run(Form mainForm)
         at WindowsFormsApplication4.Program.Main() in c:\Users\tiago\Documents\Visual Studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Program.cs:line 19
         at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()
    InnerException: System.InvalidOperationException
         HResult=-2146233079
         Message=There is an error in XML document (1, 273).
         Source=System.Xml
         StackTrace:
              at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
              at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
         InnerException: System.InvalidOperationException
              HResult=-2146233079
              Message=The specified type was not recognized: name='Car', namespace='http://ws.kontrol.aiko.com/', at &lt;item xmlns=''&gt;.
              Source=Microsoft.GeneratedCode
              StackTrace:
                   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderTestWebService.Read3_Animal(Boolean isNullable, Boolean checkType)
                   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderTestWebService.Read6_getVehiclesResponse()
                   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)
                   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
              InnerException: 
  </code></pre>
  
  <p><strong>Soap WSDL:</strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.kontrol.aiko.com/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="TestWebServiceService" targetNamespace="http://ws.kontrol.aiko.com/"&gt;
    &lt;wsdl:types&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ws.kontrol.aiko.com/" targetNamespace="http://ws.kontrol.aiko.com/" version="1.0"&gt;
  
    &lt;xs:complexType name="Animal"&gt;
      &lt;xs:sequence/&gt;
      &lt;xs:attribute name="AnimalProp" type="xs:string"/&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType name="Dog"&gt;
      &lt;xs:complexContent&gt;
        &lt;xs:extension base="tns:Animal"&gt;
          &lt;xs:sequence/&gt;
          &lt;xs:attribute name="DogProp" type="xs:string"/&gt;
        &lt;/xs:extension&gt;
      &lt;/xs:complexContent&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType name="Vehicle"&gt;
      &lt;xs:sequence/&gt;
      &lt;xs:attribute name="VechicleProp" type="xs:string"/&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType name="Car"&gt;
      &lt;xs:complexContent&gt;
        &lt;xs:extension base="tns:Vehicle"&gt;
          &lt;xs:sequence/&gt;
          &lt;xs:attribute name="CarProp" type="xs:string"/&gt;
        &lt;/xs:extension&gt;
      &lt;/xs:complexContent&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType final="#all" name="AnimalArray"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="tns:Animal"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType final="#all" name="VehicleArray"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="tns:Vehicle"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  
  &lt;/xs:schema&gt;
    &lt;/wsdl:types&gt;
    &lt;wsdl:message name="getVehiclesResponse"&gt;
      &lt;wsdl:part name="return" type="tns:VehicleArray"&gt;
      &lt;/wsdl:part&gt;
    &lt;/wsdl:message&gt;
    &lt;wsdl:message name="getAnimals"&gt;
    &lt;/wsdl:message&gt;
    &lt;wsdl:message name="getAnimalsResponse"&gt;
      &lt;wsdl:part name="return" type="tns:AnimalArray"&gt;
      &lt;/wsdl:part&gt;
    &lt;/wsdl:message&gt;
    &lt;wsdl:message name="getVehicles"&gt;
    &lt;/wsdl:message&gt;
    &lt;wsdl:portType name="TestWebService"&gt;
      &lt;wsdl:operation name="getAnimals"&gt;
        &lt;wsdl:input message="tns:getAnimals" name="getAnimals"&gt;
      &lt;/wsdl:input&gt;
        &lt;wsdl:output message="tns:getAnimalsResponse" name="getAnimalsResponse"&gt;
      &lt;/wsdl:output&gt;
      &lt;/wsdl:operation&gt;
      &lt;wsdl:operation name="getVehicles"&gt;
        &lt;wsdl:input message="tns:getVehicles" name="getVehicles"&gt;
      &lt;/wsdl:input&gt;
        &lt;wsdl:output message="tns:getVehiclesResponse" name="getVehiclesResponse"&gt;
      &lt;/wsdl:output&gt;
      &lt;/wsdl:operation&gt;
    &lt;/wsdl:portType&gt;
    &lt;wsdl:binding name="TestWebServiceServiceSoapBinding" type="tns:TestWebService"&gt;
      &lt;soap12:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
      &lt;wsdl:operation name="getAnimals"&gt;
        &lt;soap12:operation soapAction="" style="rpc"/&gt;
        &lt;wsdl:input name="getAnimals"&gt;
          &lt;soap12:body namespace="http://ws.kontrol.aiko.com/" use="literal"/&gt;
        &lt;/wsdl:input&gt;
        &lt;wsdl:output name="getAnimalsResponse"&gt;
          &lt;soap12:body namespace="http://ws.kontrol.aiko.com/" use="literal"/&gt;
        &lt;/wsdl:output&gt;
      &lt;/wsdl:operation&gt;
      &lt;wsdl:operation name="getVehicles"&gt;
        &lt;soap12:operation soapAction="" style="rpc"/&gt;
        &lt;wsdl:input name="getVehicles"&gt;
          &lt;soap12:body namespace="http://ws.kontrol.aiko.com/" use="literal"/&gt;
        &lt;/wsdl:input&gt;
        &lt;wsdl:output name="getVehiclesResponse"&gt;
          &lt;soap12:body namespace="http://ws.kontrol.aiko.com/" use="literal"/&gt;
        &lt;/wsdl:output&gt;
      &lt;/wsdl:operation&gt;
    &lt;/wsdl:binding&gt;
    &lt;wsdl:service name="TestWebServiceService"&gt;
      &lt;wsdl:port binding="tns:TestWebServiceServiceSoapBinding" name="TestWebServicePort"&gt;
        &lt;soap12:address location="http://localhost:8080/app/TestWebService"/&gt;
      &lt;/wsdl:port&gt;
    &lt;/wsdl:service&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p><strong><code>getVehicles</code> response:</strong></p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;soap:Body&gt;
          &lt;ns1:getVehiclesResponse xmlns:ns1="http://ws.kontrol.aiko.com/"&gt;
              &lt;return&gt;
                  &lt;item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://ws.kontrol.aiko.com/" xsi:type="ns3:Car"/&gt;
              &lt;/return&gt;
          &lt;/ns1:getVehiclesResponse&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p><strong>Auto generated C# code:</strong> <a href="https://gist.github.com/anonymous/ae9a42fb146b159a4ccd" rel="nofollow">https://gist.github.com/anonymous/ae9a42fb146b159a4ccd</a></p>
  
  <p><strong>App.config:</strong> <a href="https://gist.github.com/anonymous/e5a311bd0e779f592ac0" rel="nofollow">https://gist.github.com/anonymous/e5a311bd0e779f592ac0</a></p>
  
  <p><strong>Test code:</strong></p>
  
  <pre><code>ServiceReference.TestWebServiceClient client = new ServiceReference.TestWebServiceClient();
  Animal[] sensors = client.getAnimals();
  Vehicle[] vehicles = client.getVehicles(); //THIS LINE THROWS THE EXCEPTION
  </code></pre>
  
  <p><strong>Service Reference Settings:</strong> <a href="http://i.stack.imgur.com/vuOMi.png" rel="nofollow">http://i.stack.imgur.com/vuOMi.png</a></p>