0
votes

I get the following error on runtime: AmbiguousMatchExcpetion "Ambiguous Match found."

Does someone knows what is the reason for?

Class

public class MyTrimmedClass : Control, INotifyPropertyChanged
{
    public HtUserGroupSetup CurrentUserGroupSetup
    {
        get { return _CurrentUserGroupSetup; }
        set
        {
            if (_CurrentUserGroupSetup != value)
            {
                _CurrentUserGroupSetup = value;
                OnPropertyChanged();
            }
        }
    }
    private HtUserGroupSetup _CurrentUserGroupSetup;


    public event PropertyChangedEventHandler PropertyChanged;

    [NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}


public class HtUserGroupSetup : HtUserGroup
{
    public new List<HtPermissionSetup> Permissions
    {
        get { return _Permissions; }
        set
        {
            if (_Permissions != value)
            {
                _Permissions = value;
                OnPropertyChanged("Permissions");
            }
        }
    }
    private List<HtPermissionSetup> _Permissions = new List<HtPermissionSetup>();

    public HtUserGroupSetup(HtUserGroup userGroup)
    {
        Name = userGroup.Name;
        Description = userGroup.Description;
    }
}

public class HtUserGroup : HtBaseServiceData
{
    private string _Name = "";
    [DataMember]
    public string Name
    {
        get { return _Name; }
        set
        {
            if (_Name != value)
            {
                _Name = value;
                OnPropertyChanged("Name");
            }
        }
    }

    private string _Description = "";
    [DataMember]
    public string Description
    {
        get { return _Description; }
        set
        {
            if (_Description != value)
            {
                _Description = value;
                OnPropertyChanged("Description");
            }
        }
    }

    private List<HtPermission> _Permissions = new List<HtPermission>();
    [DataMember]
    public List<HtPermission> Permissions
    {
        get { return _Permissions; }
        set
        {
            if (_Permissions != value)
            {
                _Permissions = value;
                OnPropertyChanged("Permissions");
            }
        }
    }
}

public abstract class HtBaseServiceData : INotifyPropertyChanged
{
    protected void OnPropertyChanged(string property)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
    }
    public event PropertyChangedEventHandler PropertyChanged;
}

Screenshot

Screenshot

StackTrace

System.Reflection.AmbiguousMatchException ist aufgetreten.

HResult=-2147475171 Message=Mehrdeutige Übereinstimmung gefunden.
Source=mscorlib StackTrace: bei System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) InnerException:

StackTrace

1
You should post the entire exception including the stack - Ofir Winegarten
@OfirWinegarten postet it. - Dominic Jonas
Add the whole class please - Samvel Petrosov
You will need to add more context. Also, avoid posting screenshots. Post code/text instead. stackoverflow.com/help/how-to-ask - jeroenh
Most likely error happens in the handler of PropertyChanged event, so not related to CallerMemberName. But hard to say without full stack trace (what is posted now is not full, because includes only last call). Ensure that you don't have properties with the same names but different casing in your class (like CurrentUserGroupSetup and currentUserGroupSetup). - Evk

1 Answers

1
votes

The problem is, that the Permissions property in HtUserGroupSetup was hiding the Permissions property of the baseClass (HtUserGroup).

public new List<HtPermissionSetup> Permissions

Renaming the Permissions property in HtUserGroupSetup solved the problem.