[Mono-list] Bug in XmlSerializer with hidden method

Terry thenn@sbcglobal.net
Tue, 5 Aug 2003 22:04:22 -0500


I came across this kind of by accident.  I wanted to have a typed return
from an ArrayList and I was already using ArrayList so I just created my own
class and derived it from ArrayList.  I used the "new" keyword to hide the
array indexer and cast the return to a string.  (I know!  I would not do
this for real, but I was just testing something to see if it would work.
:-)  I create an object of the derived class, add a few strings and
XmlSerialize it to disk.  Under Window's .NET framework 1.1 it generates an
.xml file with the strings I added.  Under Mono/RH9 I get a "Ambiguous
matching in method resolution" error.

I know this is terrible code, but technically I think it should still work.

Below is a test program I've found duplicates the problem.  This works ok on
Windows with the following XML output:

[WINDOWS XP Pro on .NET 1.1]
<?xml version="1.0"?>
<ArrayOfAnyType xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <anyType xsi:type="xsd:string">Test1</anyType>
  <anyType xsi:type="xsd:string">Test2</anyType>
  <anyType xsi:type="xsd:string">Test3</anyType>
</ArrayOfAnyType>

[MONO 0.25 on RedHat 9]
[sish@localhost sish]$ mono MethodHideTest.exe
Ambiguous matching in method resolution
in <0x001ee> 00 System.MonoType:GetPropertyImpl
(string,System.Reflection.BindingFlags,System.Reflection.Binder,System.Type,
System.Type[],System.Reflection.ParameterModifier[])
in <0x00070> 00 System.Type:GetProperty (string)
in <0x00222> 00
System.Xml.Serialization.XmlSerializationWriterInterpreter:WriteListContent
(System.Xml.Serialization.TypeData,System.Xml.Serialization.ListMap,object)
in <0x00190> 00
System.Xml.Serialization.XmlSerializationWriterInterpreter:WriteListElement
(System.Xml.Serialization.XmlTypeMapping,object,string,string)
in <0x00308> 00
System.Xml.Serialization.XmlSerializationWriterInterpreter:WriteObject
(System.Xml.Serialization.XmlTypeMapping,object,string,string,bool,bool,bool
)
in <0x00145> 00
System.Xml.Serialization.XmlSerializationWriterInterpreter:WriteObject
(object)
in <0x0000e> 00 System.Xml.Serialization.XmlSerializer:Serialize
(object,System.Xml.Serialization.XmlSerializationWriter)
in <0x00045> 00 System.Xml.Serialization.XmlSerializer:Serialize
(System.Xml.XmlWriter,object,System.Xml.Serialization.XmlSerializerNamespace
s)
in <0x00070> 00 System.Xml.Serialization.XmlSerializer:Serialize
(System.IO.Stream,object)
in <0x0010d> 00 MethodHideTest.Class1:Main (string[])

-----------------
[The test program]
file: "Class1.cs"

using System;
using System.Xml.Serialization;
using System.IO;

namespace MethodHideTest
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			MyArrayList myList = new MyArrayList();

			myList.Add("Test1");
			myList.Add("Test2");
			myList.Add("Test3");

			XmlSerializer xs = new XmlSerializer(typeof(MyArrayList) );

			FileStream fs = null;

			try
			{
				fs = File.Open("testout.xml", FileMode.Create, FileAccess.Write);
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				return;
			}

			try
			{
				xs.Serialize(fs, myList);
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
				Console.WriteLine(ex.InnerException);
				Console.WriteLine(ex.StackTrace);
				return;
			}
			finally
			{
				fs.Close();
			}

			Console.WriteLine("Hit 'Enter' to exit...");
			Console.ReadLine();
		}
	}
}

file: "MyArrayList.cs"

using System;

namespace MethodHideTest
{
	/// <summary>
	///
	/// </summary>
	public class MyArrayList : System.Collections.ArrayList
	{
		public MyArrayList()
			: base()
		{
		}

		public new object this[ int index ]
		{
			get
			{
				return (string)base[index];
			}
		}

	}
}