Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WPF application which has a property grid. I am binding the property grid with a class object (say the class name is "mainclass"). The "mainclass" has a property "APIConditions" which is an Observable collection of another custom class "SearchAPIModel". "SearchAPIModel" has a property of observablecollection of class "KeyValues". I have added an item to the "APIConditions" collection using the UI of property grid. The newly added object to the collection is saving successfully. But the problem I am facing is, I am able to bind the "main class" object to the property grid but when I am trying to open the "APIConditions" property which is supposed to open in a popupwindow, the application crashes with the error
"An unhandled exception of type 'System.Reflection.TargetParameterCountException' occurred in PresentationFramework.dll
Additional information: Parameter count mismatch."

Can anyone explain why this issue occurs and what is the solution for this ?.

Thanks in advance,
Rasheed

What I have tried:

Please see the classes as below.
C#
[Serializable]
public class MainClass : INotifyPropertyChanged, INotifyCollectionChanged
{
    private string _SelectText, _ID;      
    private ObservableCollection<searchapimodel> _APIConditions;       
    public event PropertyChangedEventHandler PropertyChanged;
    public event NotifyCollectionChangedEventHandler CollectionChanged;
   
    private void OnNotifyPropertyChanged(string propertyName)
    {
        var tmp = PropertyChanged;
        if (tmp != null)
        {
            tmp(this, new PropertyChangedEventArgs(propertyName));
        }
    }      
  
    [CategoryAttribute("TextBox Details"), DefaultValueAttribute(true), DescriptionAttribute("ID of the TextBox control"), ReadOnly(true)]
    public string ID
    {
        get { return _ID; }
        set
        {

            if (_ID != value)
            {
                _ID = value;
            }
        }
    }

    [CategoryAttribute("LookupOption Details"), DefaultValueAttribute(true), DescriptionAttribute("Initial Text For Lookup And Nothing is Selected"), ReadOnly(false)]
    public string SelectText
    {
        get { return _SelectText; }
        set
        {
            if (_SelectText != value)
            {
                _SelectText = value;                   
            }
        }
    }

    [CategoryAttribute("LookupOption Details"), DefaultValueAttribute(true), DescriptionAttribute("Collection Of SearchAPIModel.")]
    public ObservableCollection<searchapimodel> APIConditions
    {
        get { return _APIConditions; }
        set
        {
            if (_APIConditions != value)
            {
                _APIConditions = value;
            }
        }
    }
    public MainClass()
    {
        this.SelectText = "[SELECT]";
        this.ID = "";
        this.APIConditions = new ObservableCollection<searchapimodel>();
    }
}

SearchAPIModel class
C#
[Serializable]
public class SearchAPIModel : INotifyPropertyChanged, INotifyCollectionChanged
{

    private string _ConditionRow;
    public event PropertyChangedEventHandler PropertyChanged;
    public event NotifyCollectionChangedEventHandler CollectionChanged;
    
    private ObservableCollection<keyvalues> _SearchTextList;        
    
    private void OnNotifyPropertyChanged(string propertyName)
    {
        var tmp = PropertyChanged;
        if (tmp != null)
        {
            tmp(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    [CategoryAttribute("API Condition Details"), DefaultValueAttribute(true), DescriptionAttribute("ConditionRow")]
    public string ConditionRow
    {
        get { return _ConditionRow; }
        set
        {
            if (_ConditionRow != value)
            {
                _ConditionRow = value;
                OnNotifyPropertyChanged("");
            }
        }
    }

    [CategoryAttribute("API Condition Details"), DefaultValueAttribute(true), DescriptionAttribute("SearchTextList")]
    public ObservableCollection<keyvalues> SearchTextList
    {
        get { return _SearchTextList; }
        set
        {
            _SearchTextList = value;
            if (_SearchTextList != value)
            {
                _SearchTextList = value;
            }
        }
    }

    public SearchAPIModel()
    {
        this.ConditionRow = "";
        this.SearchTextList = new ObservableCollection<keyvalues>();            
    }
  
}

KeyValues class
C#
[Serializable]
public class KeyValues : INotifyPropertyChanged
{
    private string _key, _Value;
    [ReadOnly(false)]
    public string Key
    {
      get { return _key; }
      set { _key = value;  }
    }
    [ReadOnly(false)]
    public string Value
    {
        get { return _Value; }
        set { _Value = value; }
    }

    public KeyValues()
    {
        Key = "";
        Value = "";
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void OnNotifyPropertyChanged()
    {
        var tmp = PropertyChanged;
        if (tmp != null)
        {
            tmp(this, new PropertyChangedEventArgs(""));
        }
    }
}
Posted
Updated 23-Mar-17 20:51pm
v2

1 solution

According to TargetParameterCountException Class (System.Reflection)[^]:
Quote:
The exception that is thrown when the number of parameters for an invocation does not match the number expected.

Looking at the error message at face value, what you are passing to not what is expected.

You need to identify the line that this error is thrown on before you can start looking for solutions. We don't know which line this occurs on or what is expected unless more information is provided.

Once you are ready update the question with clear and concise details, sample code, any error messages (including inner exception details), etc, please click on Improve question to add more info to the question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900