Bug 2893 - XmlSerializationWriterInterpreter.WriteAnyElementContent isn't checking for arrays of XmlNode
Summary: XmlSerializationWriterInterpreter.WriteAnyElementContent isn't checking for a...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-01-13 14:44 UTC by Tom Hindle
Modified: 2012-01-14 15:37 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
proposed patch to fix issue. (811 bytes, patch)
2012-01-13 14:47 UTC, Tom Hindle
Details
Simple contrived test program showing issue (1002 bytes, text/plain)
2012-01-13 22:09 UTC, Tom Hindle
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Tom Hindle 2012-01-13 14:44:33 UTC
MSDN says that XmlAnyElement can be an array of XmlElement or XmlNode: http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlanyelementattribute(v=vs.71).aspx
Comment 1 Tom Hindle 2012-01-13 14:47:32 UTC
Created attachment 1189 [details]
proposed patch to fix issue.
Comment 2 Miguel de Icaza [MSFT] 2012-01-13 15:44:05 UTC
Tom,

Would you mind providing a test case that shows how this is failing currently?

Additionally, it would be nice to have a test to ensure that we do not regress in the future.

I want to wait to apply the patch, because I want to see the failure first on Mono, and compare with Windows.
Comment 3 Tom Hindle 2012-01-13 22:09:27 UTC
Created attachment 1192 [details]
Simple contrived test program showing issue

Attached is a contrived test case showing the issue. 

.net output:

?<?xml version="1.0" encoding="utf-8"?><Comment /><?xml version="1.0"?>
<Comment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:/
/www.w3.org/2001/XMLSchema" />

mono on windows (2.10.2) output:

Unhandled Exception: System.InvalidOperationException: There was an error genera
ting the XML document. ---> System.InvalidCastException: Cannot cast from source
 type to destination type.
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteAnyElementC
ontent (System.Xml.Serialization.XmlTypeMapMemberAnyElement member, System.Objec
t memberValue) [0x00026] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.2\mcs\
class\System.XML\System.Xml.Serialization\XmlSerializationWriterInterpreter.cs:4
75
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMemb
ers (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean isValueLis
t) [0x000c5] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.2\mcs\class\System
.XML\System.Xml.Serialization\XmlSerializationWriterInterpreter.cs:256
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectEleme
ntElements (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob) [
0x0000c] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.2\mcs\class\System.XML
\System.Xml.Serialization\XmlSerializationWriterInterpreter.cs:198
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectEleme
nt (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, System.St
ring element, System.String namesp) [0x00036] in C:\cygwin\tmp\monobuild\build\B
UILD\mono-2.10.2\mcs\class\System.XML\System.Xml.Serialization\XmlSerializationW
riterInterpreter.cs:186
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject (Sys
tem.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob, System.String el
ement, System.String namesp, Boolean isNullable, Boolean needType, Boolean write
WrappingElem) [0x001c4] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.2\mcs\c
lass\System.XML\System.Xml.Serialization\XmlSerializationWriterInterpreter.cs:15
0
  at System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteRoot (Syste
m.Object ob) [0x00056] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.2\mcs\cl
ass\System.XML\System.Xml.Serialization\XmlSerializationWriterInterpreter.cs:75

  at System.Xml.Serialization.XmlSerializer.Serialize (System.Object o, System.X
ml.Serialization.XmlSerializationWriter writer) [0x0001c] in C:\cygwin\tmp\monob
uild\build\BUILD\mono-2.10.2\mcs\class\System.XML\System.Xml.Serialization\XmlSe
rializer.cs:414
  at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter writ
er, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces
) [0x00064] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.2\mcs\class\System.
XML\System.Xml.Serialization\XmlSerializer.cs:480
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter writ
er, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces
) [0x000a0] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.2\mcs\class\System.
XML\System.Xml.Serialization\XmlSerializer.cs:487
  at XmlAnyElementTest.Test.SerializeObject (XmlAnyElementTest.Comment obj) [0x0
004c] in XmlAnyElementTest\Program.cs:39
 at XmlAnyElementTest.Test.Main () [0x00007] in XmlAnyElementTest\Program.cs:24



(writing regression/unit test is on my TODO list)
Comment 4 Miguel de Icaza [MSFT] 2012-01-14 15:37:37 UTC
Thanks for the test case

I have added a unit test case based on your test.

Fixed on mono-2-10 and master