Note that there are some explanatory texts on larger screens.

plurals
  1. POXML Serialization: System.InvalidOperationException: <tagname> was not expected
    primarykey
    data
    text
    <p>I'm trying to de-serialize an XML Document and when the desserializer encounters a certain tag about halfway down the doc, it gives the error: </p> <pre><code>System.InvalidOperationException &lt;mytagname&gt; was not expected. </code></pre> <p>It has a <code>[System.Xml.Serialization.XmlArrayItemAttribute("MyTagName", typeof(MediaFile))]</code> tag right before it in the class, and the error is only happening on this one particular tag/class, but I can't find anything different about it that would make this occur. Anyone ever seen this before? </p> <p><strong>EDITED FOR MORE DETAIL:</strong></p> <p>Here's the deserializer code:</p> <pre><code> String xmlString = _doc.ToString(); StringReader sr = new StringReader(xmlString); XmlReader xr = XmlReader.Create(sr); xs = new XmlSerializer(typeof(VideoAdServingTemplate&lt;AdNode&gt;)); objVast = (VideoAdServingTemplate&lt;AdNode&gt;)xs.Deserialize(sr); </code></pre> <p>And the XML in question looks like this:</p> <pre><code>&lt;VideoAdServingTemplate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd"&gt; &lt;Ad id="myad"&gt; &lt;InLine&gt; &lt;AdSystem&gt;MyAdSystem&lt;/AdSystem&gt; &lt;AdTitle&gt;Advertisement&lt;/AdTitle&gt; &lt;Description&gt;Shamwow&lt;/Description&gt; &lt;Survey&gt; &lt;URL&gt;&lt;![CDATA[http://www.dynamiclogic.com/tracker?campaignId=234&amp;site=yahoo]]&gt;&lt;/URL&gt; &lt;/Survey&gt; &lt;Error&gt; &lt;URL&gt;&lt;![CDATA[http://www.primarysite.com/tracker?noPlay=true&amp;impressionTracked=false]]&gt;&lt;/URL&gt; &lt;/Error&gt; &lt;Impression&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?imp]]&gt;&lt;/URL&gt; &lt;URL id="anotheradsever"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?imp]]&gt;&lt;/URL&gt; &lt;/Impression&gt; &lt;TrackingEvents&gt; &lt;Tracking event="start"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?start]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="midpoint"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?mid]]&gt;&lt;/URL&gt; &lt;URL id="anotheradsever"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?mid]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="firstQuartile"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?fqtl]]&gt;&lt;/URL&gt; &lt;URL id="anotheradsever"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?fqtl]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="thirdQuartile"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?tqtl]]&gt;&lt;/URL&gt; &lt;URL id="anotheradsever"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?tqtl]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="complete"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?comp]]&gt;&lt;/URL&gt; &lt;URL id="anotheradsever"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?comp]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="mute"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?mute]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="pause"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?pause]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="replay"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?replay]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="fullscreen"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?full]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;Tracking event="stop"&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?stop]]&gt;&lt;/URL&gt; &lt;/Tracking&gt; &lt;/TrackingEvents&gt; &lt;Video&gt; &lt;Duration&gt;00:00:15&lt;/Duration&gt; &lt;AdID&gt;AdID&lt;/AdID&gt; &lt;VideoClicks&gt; &lt;ClickThrough&gt; &lt;URL id="myadsever"&gt;&lt;![CDATA[http://www.primarysite.com/tracker?click]]&gt;&lt;/URL&gt; &lt;/ClickThrough&gt; &lt;ClickTracking&gt; &lt;URL id="anotheradsever"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?click]]&gt;&lt;/URL&gt; &lt;URL id="athirdadsever"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?click]]&gt;&lt;/URL&gt; &lt;/ClickTracking&gt; &lt;CustomClick&gt; &lt;URL id="redclick"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?click]]&gt;&lt;/URL&gt; &lt;URL id="blueclick"&gt;&lt;![CDATA[http://www.thirdparty.com/tracker?click]]&gt;&lt;/URL&gt; &lt;/CustomClick&gt; &lt;/VideoClicks&gt; &lt;MediaFiles&gt; &lt;MediaFile delivery="streaming" bitrate="250" width="200" height="200" type="video/x-flv"&gt; &lt;URL&gt;&lt;![CDATA[rtmp://streamingserver/streamingpath/medium/filename.flv]]&gt;&lt;/URL&gt; &lt;/MediaFile&gt; &lt;MediaFile delivery="progressive" bitrate="400" width="200" height="200" type="video/x-flv"&gt; &lt;URL&gt;&lt;![CDATA[http://progressive.hostlocation.com//high/filename.flv]]&gt;&lt;/URL&gt; &lt;/MediaFile&gt; &lt;MediaFile delivery="progressive" bitrate="200" width="200" height="200" type="video/x-flv"&gt; &lt;URL&gt;&lt;![CDATA[http://progressive.hostlocation.com/progressivepath/medium/filename.flv]]&gt;&lt;/URL&gt; &lt;/MediaFile&gt; &lt;!-- and a few more MediaFile tags --&gt; &lt;/MediaFiles&gt; &lt;/Video&gt; </code></pre> <p>There's a bit more to the XML but its pretty big so I cut a lot out of it. I'm not sure of the order in which everything is deserialized, all I know is the first error I see after calling xs.Deserialize() is:</p> <pre><code>Unhandled Error in Silverlight 2 Application Code: 4004 Category: ManagedRuntimeError Message: System.InvalidOperationException: There is an error in XML document (1, 7). ---&gt; System.InvalidOperationException: &lt;MediaFile xmlns=''&gt; was not expected. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderVideoAdServingTemplate1.Read27_VideoAdServingTemplate() --- End of inner exception stack trace --- at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, Object events) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader) </code></pre> <p>There's no indication of what was expected or why this wasn't expected. </p> <p>The class that implements it has this definition to associate the tag with an object:</p> <pre><code> [System.Xml.Serialization.XmlArrayItemAttribute("MediaFile", typeof(MediaFile))] public MediaFile[] MediaFiles { get { return this.mediaFilesField; } set { this.mediaFilesField = value; } } </code></pre> <p>I assume that the [] in the definition and the use of XmlArrayItemAttribute is because there are multiple MediaFile tags in a row, so they are being placed into an array. I generated this code with xsd.exe and modified it slightly to work in Silverlight. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload