views:

264

answers:

2

EDIT: See Pavel's answer below -- the 'type not recognized error' was caused by a mismatch between the class heirarchy in my parsing code (which I did not include here) and my XML schema. The 'type not recognized' error was something of a red herring, but once I fixed things the parsing works just fine. If you get to this question because you've googled for that error message, triple-check your heirarchies!

I have the XML file shown below. When I view it in VS2008, Intellisense does not report any errors. However when I try to parse it with XmlSerializer.Deserialize, I get the exception:

The specified type was not recognized: name='UTCTimeStamp_t', namespace='http://www.fixprotocol.org/ATDL-1-1/Core', at <Parameter xmlns='http://www.fixprotocol.org/ATDL-1-1/Core'&gt;.

(The offending xsi:Type, "UTCTimeStamp_t", is defined in the referenced XSD file as shown below the XML.)

Why does XmlSerializer reject the XML even though Intellisense shows it as being valid? (I double-checked that both are getting the same copy of the XSD file.)

Is there a change I can make, or a workaround I can apply, to get this to parse?

NOTE: I am doing this in Silverlight3 -- are there any particular limitations to that version of the serializer?

Here's the XML:

<?xml version="1.0" encoding="utf-8"?>
<Strategies
 xmlns="http://www.fixprotocol.org/ATDL-1-1/Core"
  xmlns:core="http://www.fixprotocol.org/ATDL-1-1/Core"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xsi:schemaLocation="http://www.fixprotocol.org/ATDL-1-1/Core http://www.myserver.com/atdl-core-1-1.xsd"
  strategyIdentifierTag="7620"
  >

  <Strategy name="Tazer1" uiRep="Tazer" wireValue="Tazer" version="1" fixMsgType="D" providerID="ABC">

    <Parameter name="StartTime" xsi:type="core:UTCTimeStamp_t" fixTag="7602" use="required" localMktTz="America/New_York">
      <Description>Strategy Start Time</Description>
    </Parameter>
  </Strategy>

</Strategies>

Here's the snippet of the XSD file:

  <xs:complexType name="UTCTimeStamp_t">
    <xs:complexContent>
      <xs:extension base="core:Parameter_t">
        <xs:attribute name="minValue" type="core:UTCTimeStamp"/>
        <xs:attribute name="maxValue" type="core:UTCTimeStamp"/>
        <xs:attribute name="dailyMinValue" type="core:LocalMktTime"/>
        <xs:attribute name="dailyMaxValue" type="core:LocalMktTime"/>
        <xs:attribute name="localMktTz" type="xs:string">
          <xs:annotation>
            <xs:documentation>
              These string values must correspond to time zone values from the zoneinfo database,
              also known as the tz database.
            </xs:documentation>
          </xs:annotation>
        </xs:attribute>
        <xs:attribute name="constValue" type="core:UTCTimeStamp"/>
        <xs:attribute name="dailyConstValue" type="core:LocalMktTime"/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
A: 

Please post more of your XSD.

Where do you define <Strategy>?

david valentine
+2  A: 

XmlSerializer does not care about XML Schema definition of the type - all it cares about is the name of the type, and the class declaration that maps to it. It's not possible to say what the problem is without looking at the definition of the class(es) you're trying to deserialize, complete with their XML serialization attributes.

Pavel Minaev
Thanks, Pavel. Knowing that XmlSerializer does not look at the Schema Definition was the key I needed to solve the problem. It turns out that had a mis-match between my class heirarchy and my schema, so the "type" attribute was being parsed by a totally different class than I thought it was. D'oh!
Eric