[Mono-devel-list] Reflection exception
Lluis Sanchez
lluis at ideary.com
Fri Jun 27 07:55:23 EDT 2003
Hi!
It has an easy fix. I'll try to fix it today.
- Lluis
----- Original Message -----
From: "Herscovici, Avi" <AHerscovici at Empirix.com>
To: <mono-devel-list at lists.ximian.com>
Sent: Thursday, June 26, 2003 11:21 PM
Subject: [Mono-devel-list] Reflection exception
> I got the latest code from CVS (thanks Lluis) and it fixed a lot of
> serialization things, but now I get an ambiguous matching error from
> calling the XmlSerializer constructor. Our code is complex (compiles in
> .Net fine) but I've narrowed it to what seems to be a problem with
> reflection and overloaded functions/properties. I've stripped my code
down
> to the bare minimum to illustrate what happens. Again, I'd be willing to
> work on this problem if no one has a quick fix or wants to take it up.
> Here's the code (to get rid of the problem I have to comment out all
> overloaded Add functions and this properties and only leave the ones with
a
> single parameter. Also the implementation of the methods/properties in
> script.cs is irrelevant.):
>
>
> // ------------------------------------------ file1.cs
> ------------------------------------
> using System;
> using System.Xml.Serialization;
> using System.IO;
> using System.Xml;
> using Scripts;
>
>
> namespace Serial.test {
>
> public class sertest {
>
> public static void Save(System.IO.Stream stream, object x)
> {
> XmlSerializer ser = new
> XmlSerializer(typeof(Script));
> ser.Serialize(stream, x);
> }
>
> public static void Save(string filename, object x)
> {
> FileStream str = new FileStream(filename,
> FileMode.Create, FileAccess.Write);
> Save(str, x);
> str.Close();
> }
>
> public static object Load(System.IO.Stream stream)
> {
> object s;
> Console.WriteLine("Debug line 1a");
> XmlSerializer ser = new
> XmlSerializer(typeof(Script));
> Console.WriteLine("Debug line 2a");
> // try {
> s = (object)ser.Deserialize(stream);
> // }
> // catch (Exception e) {Console.WriteLine("Exception: "
> + e);}
> // s = null;
> return s;
> }
>
>
> public static object Load(string filename)
> {
> object s;
> Console.WriteLine("Debug line 2");
> FileStream str = new FileStream(filename,
> FileMode.Open, FileAccess.Read);
> Console.WriteLine("Debug line 3");
> s = Load(str);
> Console.WriteLine("Debug line 4");
> str.Close();
> return s;
> }
> static void Main() {
> string filename = "test.ser";
> Script x = new Script();
> Save(filename, x);
> Script temp = (Script)Load(filename);
> Console.WriteLine("Finished");
> }
> }
> }
>
> // ------------------------------- Script.cs
> ----------------------------------
>
> using System;
> using System.Collections;
>
> namespace Scripts
> {
> public class Script: CollectionBase, ICloneable
> {
> public Script()
> {
> }
> public Script(Script p)
> {
> }
> public object Clone()
> {
> return new Script(this);
> }
> public void Add(object p)
> {
> InnerList.Add(p);
> }
> public void Add(string name, object value)
> {
> Add(new object());
> }
> public void Add(string[] names, string[] values)
> {
> }
> public void Add(Script collection)
> {
> }
> public object this[int index]
> {
> get
> {
> return (object)InnerList[index];
> }
> set
> {
> InnerList[index] = value;
> }
> }
> public string this[string name]
> {
> get
> {
> return this[name, true];
> }
> set
> {
> int index = 0;
> if(index != -1)
> {
> this[index] = new object();
> }
> else
> {
> Add(name, value);
> }
> }
> }
> public string this[string name, bool ignoreCase]
> {
> get
> {
> return null;
> }
> }
> }
> }
> // ------------------- END --------------------------------------------
>
> Here's the error:
>
> Unhandled Exception: System.Reflection.AmbiguousMatchException: Ambiguous
> matching in method resolution
> in <0x00148> 00 System.MonoType:GetMethodImpl
>
(string,System.Reflection.BindingFlags,System.Reflection.Binder,System.Refle
>
ction.CallingConventions,System.Type[],System.Reflection.ParameterModifier[]
> )
> in <0x0005a> 00 System.Type:GetMethod (string)
> in <0x000bd> 00 System.Xml.Serialization.TypeData:get_ListItemType ()
> in <0x000eb> 00
> System.Xml.Serialization.XmlReflectionImporter:ImportListMapping
>
(System.Type,System.Xml.Serialization.XmlRootAttribute,string,System.Xml.Ser
> ialization.XmlAttributes,int)
> in <0x0013d> 00
> System.Xml.Serialization.XmlReflectionImporter:ImportTypeMapping
> (System.Type,System.Xml.Serialization.XmlRootAttribute,string)
> in <0x000fa> 00 System.Xml.Serialization.XmlSerializer:.ctor
>
(System.Type,System.Xml.Serialization.XmlAttributeOverrides,System.Type[],Sy
> stem.Xml.Serialization.XmlRootAttribute,string)
> in <0x00021> 00 System.Xml.Serialization.XmlSerializer:.ctor (System.Type)
> in <0x0002d> 00 Serial.test.sertest:Save (System.IO.Stream,object)
> in <0x00049> 00 Serial.test.sertest:Save (string,object)
> in <0x00049> 00 Serial.test.sertest:Main ()
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
More information about the Mono-devel-list
mailing list