This is a migrated thread and some comments may be shown as answers.

Getting ArgumentNullException was unhandled

6 Answers 34 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sabuj
Top achievements
Rank 1
Sabuj asked on 11 Apr 2012, 08:08 PM
I am using Radgridview in my WPF app. The view model implements Idataerrorinfo interface. Whenever I add a new row to the radGridview I get that exception from a file called Disassembly.  Any idea what might cause this error.

Here is a screen shot

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Apr 2012, 07:13 AM
Hello,

 Can you post the stack trace?

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Sabuj
Top achievements
Rank 1
answered on 12 Apr 2012, 09:22 PM
Attached with this  is the stack trace.

I was using idataerrorinfor interface for validation which I think has caused the problem. However I am just guessing. It might not be true. 
0
Pavel Pavlov
Telerik team
answered on 13 Apr 2012, 09:34 AM
Hello Sabuj ,

Thanks for pasting the StackTrace !  Indeed the problem seems to be connected with validation .
Can you also paste the code for your ViewModel . I will try gather a small repro app here with your view model .
Once I am able to reproduce it here, either a workaround or a fix will be provided.

Kind regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Sabuj
Top achievements
Rank 1
answered on 13 Apr 2012, 10:22 PM
Thanks for your reply

Here is one of the view model

class AddConfigPropertyViewModel:ViewModelBase//,IDataErrorInfo
    {
 
        #region Private Variable
        private List<string> _dataType;

        private ObservableCollection<ConfigViewModel> _allConfig;
        private string _configProperty;

        #endregion
 
        #region Constructor
        public AddConfigPropertyViewModel(AddConfigWindow window)
        {
            //AddConfigWindow window = new AddConfigWindow();
            // TODO: Complete member initialization
            this.AddConfigWindow = window;
        }
        #endregion
 
        #region Properties
        public AddConfigWindow AddConfigWindow { get; set; }
        public string ConfigPropertyName
        {
            get
            {
                if (_configProperty == null)
                {
                    _configProperty = "";
                }
 
                return _configProperty;
            }
            set
            {
                _configProperty = value;
            }
        }
        public List<string> DataType
        {
            get
            {
                if (_dataType == null)
                {
                    _dataType = new List<String>();
                    _dataType.Add("String");
                    _dataType.Add("Number");
                }
                return _dataType;
            }
 
            set
            {
                _dataType = value;
            }
        }
 
        public ObservableCollection<ConfigViewModel> AllConfig
        {
            get
            {
                if (_allConfig == null)
                {
                    _allConfig = new ObservableCollection<ConfigViewModel>();
                }
                return _allConfig;
            }
            set
            {
                _allConfig = value;
                OnPropertyChanged("AllConfig");
            }
        }
 
         
        
        private int CurrentCollectionIndex { get; set; }
        private IEnumerable<ConfigurationProperty> Collection { get; set; }
        public bool IsControlAtTheTop { get; set; }
        #endregion
 
        #region Validation
     
 
        #endregion
 
        #region Icommand
 
        public ICommand GetConfigProperty { get { return new RelayCommand(GetConfigPropertyExecute, CanGetConfigPropertyExecute); } }
 
        bool CanGetConfigPropertyExecute()
        {
            return true;
        }
 
        void GetConfigPropertyExecute()
        {
            _allConfig = new ObservableCollection<ConfigViewModel>();
            Collection = Global.DbContext.ConfigurationProperties.
                                    Where(con => con.chrCPProperty.Contains(ConfigPropertyName)
                                        && con.chrCPProperty != "").ToList();
            //Collection = allConfigResult;
            _allConfig = AllConfig;
            _allConfig.Clear();
            int index;
            Console.Write(Collection.Count());
            for (index = 0; index  < Collection.Count(); index++)
            {
                _allConfig.Add(new ConfigViewModel(Collection.ElementAt(index)));
            }
            CurrentCollectionIndex = index;
            AllConfig = _allConfig;
            //OnPropertyChanged("AllConfig");
        }
 
 
        public ICommand AddNewConfigProperty { get { return new RelayCommand(AddNewConfigPropertyExecute, CanAddNewConfigPropertyExecute); } }
 
        bool CanAddNewConfigPropertyExecute()
        {
            //if(!HasErrors)
                return true;
            //return false;
        }
 
        void AddNewConfigPropertyExecute()
        {
            ConfigurationProperty newConfigProperty = new ConfigurationProperty();
            Global.DbContext.ConfigurationProperties.AddObject(newConfigProperty);
            ConfigViewModel cfgModel = new ConfigViewModel(newConfigProperty);
            cfgModel.IsInValid = true;
            AllConfig.Add(cfgModel);
        }
         
        public ICommand SaveConfig { get { return new RelayCommand(SaveConfigExecute, CanSaveConfigExecute); } }
        bool CanSaveConfigExecute()
        {
            if (this.AllConfig.Any(con=>con.IsInValid))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
 
        void SaveConfigExecute()
        {
            try
            {
                Global.DbContext.SaveChanges();
                MessageBox.Show("Saved!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 
        public ICommand CancelConfig { get { return new RelayCommand(CancelConfigExecute, CanCancelConfigExecute); } }
 
        bool CanCancelConfigExecute()
        
            return true;
        }
 
        void CancelConfigExecute()
        {
            AddConfigWindow.Close();
        }
        #endregion
    }

        Another View model
class ConfigViewModel : ViewModelBase, IDataErrorInfo
{
     
 
    #region private variables
 
    private ConfigurationProperty _configurationPropertyEntity;
    //private string _configPropertyName;
    private static List<string> _existingConfigPropertyList;
     
    //private bool _hasError;
    private List<string> _dataType;
    #endregion
 
    #region constructor
 
    public ConfigViewModel(ConfigurationProperty configEntity)
    {
        ConfigurationPropertyEntity = configEntity;
        IsInValid = false;
    }
    #endregion
 
    #region properties
    public List<string> DataType
    {
        get
        {
            if (_dataType == null)
            {
                _dataType = new List<String>();
                _dataType.Add("String");
                _dataType.Add("Number");
            }
            return _dataType;
        }
        set
        {
            _dataType = value;
        }
    }
 
 
    public bool IsInValid
    {
        get;
        set;
    }
    [Required(ErrorMessage = "Field 'PartConfigName' is required.")]
    public string PartConfigName
    {
 
        get
        {
            //if (ConfigurationPropertyEntity == null || ConfigurationPropertyEntity.chrCPProperty == null)
            //{
            //    _configPropertyName = "";
            //}
            //else
            //{
            //    _configPropertyName = ConfigurationPropertyEntity.chrCPProperty;
            //}
            return ConfigurationPropertyEntity.chrCPProperty;
        }
        set
        {
            IsInValid = true;
            if (value == string.Empty || value == "")
                throw new ArgumentException("Name cannot be null or empty");
            else if (ExistingConfigPropertyList.Where(con => con == value).Count() > 0)
            {
                throw new ArgumentException("Config prop already exist");
                //result = "Config prop already exist";
                //System.IO.File.AppendAllText("C:\\temp\\log.txt", "PartConfigName: " + PartConfigName + "\r\n");
            }
            else
            {
                IsInValid = false;
                ConfigurationPropertyEntity.chrCPProperty = value;
                _existingConfigPropertyList = ExistingConfigPropertyList;
                _existingConfigPropertyList.Add(ConfigurationPropertyEntity.chrCPProperty);
                ExistingConfigPropertyList = _existingConfigPropertyList;
                //Global.DbContext.ConfigurationProperties.AddObject(ConfigurationPropertyEntity);
            }
            OnPropertyChanged("PartConfigName");  
        }
    }
 
    public string ValidationMessage { get; set; }
    public ConfigurationProperty ConfigurationPropertyEntity
    {
        get
        {
            return _configurationPropertyEntity;
        }
 
        set
        {
            _configurationPropertyEntity = value;
        }
 
    }
 
    public string SelectedDataType
    {
        get
        {
            if (ConfigurationPropertyEntity.bitCPIsNumeric)
                return "Number";
            else
                return "String";
        }
        set
        {
            if (String.Compare(value, "Number") == 0)
                ConfigurationPropertyEntity.bitCPIsNumeric = true;
            else
                ConfigurationPropertyEntity.bitCPIsNumeric = false;
            OnPropertyChanged("SelectedDataType");
        }
    }
     
    public static List<string> ExistingConfigPropertyList
    {
        get
        {
            if (_existingConfigPropertyList == null)
            {
               _existingConfigPropertyList = new List<string>();
                var configPropertyList = Global.DbContext.ConfigurationProperties.Select(con => con.chrCPProperty);
                _existingConfigPropertyList = configPropertyList.ToList();
            }
            return _existingConfigPropertyList;
        }
        set
        {
            _existingConfigPropertyList = value;
            //OnPropertyChanged("ExistingConfigPropertyList");
        }
    }
 
     
    #endregion
 
    #region validation
    public string Error
    {
        get { throw new NotImplementedException(); }
 
    }
 
    public string this[string columnName]
    {
        get
        {
            string result = null;
           

                if (columnName == "PartConfigName")
                {
                    if (string.IsNullOrEmpty(PartConfigName))
                        result = "Please enter a name";
                    else if (ExistingConfigPropertyList.Where(con => con == PartConfigName).Count() > 1)
                    {
                        result = "Config prop already exist";
                        //System.IO.File.AppendAllText("C:\\temp\\log.txt", "PartConfigName: " + PartConfigName + "\r\n");
                    }
                   
                }

            return result;
        }
    }
 
    #endregion

}

0
Pavel Pavlov
Telerik team
answered on 18 Apr 2012, 09:56 AM
Hello Sabuj ,

We were trying to reproduce the problem locally using your code. However still we were not able to get the exception you have mentioned.  As alternative I may offer the following way to further assist you: If you can attach a small repro project that exposes the exception I will be glad to debug it and get back to you with either a workaround or a fix.

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Sabuj
Top achievements
Rank 1
answered on 20 Apr 2012, 04:56 PM
Thanks for your reply. Right now is not possible for me to create a small repro project. However I have work around the issue and it works okay. I have another question though, will post seperate ticket for it. 
Tags
General Discussions
Asked by
Sabuj
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Sabuj
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or