0

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

Dominic Jonas
  • 4,717
  • 1
  • 34
  • 77
  • 1
    You should post the entire exception including the stack – Ofir Winegarten May 17 '17 at 06:47
  • @OfirWinegarten postet it. – Dominic Jonas May 17 '17 at 06:53
  • Add the whole class please – Samvel Petrosov May 17 '17 at 06:59
  • 1
    You will need to add more context. Also, avoid posting screenshots. Post code/text instead. https://stackoverflow.com/help/how-to-ask – jeroenh May 17 '17 at 07:00
  • Is this enough context? @jeroenh I have already postet the `StackTrace` as code, but with a screenshot you see some more details.. – Dominic Jonas May 17 '17 at 07:32
  • Please read the article I linked to on how to ask a question. How can we reproduce the problem? Can you provide a minimal, working, concise code example that reproduces it? What have you done yourself to try an narrow down the problem? – jeroenh May 17 '17 at 07:42
  • I think you're causing an infinite loop in `MyTrimmedClass`. If it's doing what I think it is, you're not only notifying the subscribers to `PropertyChanged`, but you're also notifying the `INotifyPropertyChanged` aspect of `MyTrimmedClass`, thus causing an infinite loop. – Fireboyd78 May 17 '17 at 07:44
  • 1
    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 May 17 '17 at 08:24
  • @Evk I have found the problem. I'm "overriding" the `Permissions` Property of the base class in `HtUserGroupSetup` with "public new List Permissions", but not the solution yet. – Dominic Jonas May 17 '17 at 08:35

1 Answers1

1

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.

Dominic Jonas
  • 4,717
  • 1
  • 34
  • 77