[rdnzl-devel] .NET error : Ambiguous match found.

Iver Odin Kvello iverodin at gmail.com
Thu Apr 3 10:17:38 UTC 2008


> I think that's supposed to be  wrong.

.. or possibly not. This error can be reproduced with a pair of
classes like this:
   public class TestPropertiesA
    {
        public int thisthing = 1;
        public int MyProperty
        { get { return thisthing; }
          set { thisthing = value; }
        }
    }

    public class TestPropertiesB : TestPropertiesA
    {
        public String thisstring = "hello";
        public new String MyProperty
        {
            get { return thisstring; }
            set { thisstring = value; }
        }
    }

Notice the "new" keyword in there. When instantiated, a
TestPropertiesB-object will have both properties, and GetProperty will
indeed report an ambiguos match even though the first property was
supposed to be 'hidden'. Pretty silly. GetMethod does the correct
thing wrt the accessor method, which is why 'get_PropertyName' works.

For this case, Type.GetProperty has an overloaded form that takes the
expected return argument so probably this could be accounted for in
that way.



More information about the rdnzl-devel mailing list