ArgumentException: Property with name "XYZ" cannot be found on type "ABC"

4 posts, 0 answers
  1. Ivan
    Ivan avatar
    46 posts
    Member since:
    Nov 2013

    Posted 08 Feb Link to this post

    Hello,

    i used RadGridView to show some items. I have defined some columns of RadGridView and bind ItemsSource with list of ViewModelABC, which is a type of IViewModel.

    public interface IViewModel
    {      
    }
    public Class ViewModelABC : IViewModel
    {
        public string PropertyA { get; set; }
        public string PropertyB { get; set; }
        public string PropertyC { get; set; }
    }
    public Class MyData
    {
        public MyData()
        {
            MyItems = new List<IViewModel>();

            // MyItems could be filled with ViewModelABC

            //MyItems.Add(new ViewModelABC());

        }
        public IList<IViewModel> MyItems {get;set;}
    }

    ViewModelABC has implemented the interface IViewModel and some properties.

    When i start the application without Items, that meas, my MyData as DataContext is initialized, but it has no entry for ItemsSource in MyItems. Then i get ArgumentException from each column. "Property with name 'PropertyA' cannot be found on type 'IViewModel'.

    I don't want to defined the list with type ViewModelABC. Is there another way to avoid the ArgumentException?

     

    Thanks a lot.

    Regards,

    Ivan

  2. Stefan X1
    Admin
    Stefan X1 avatar
    756 posts

    Posted 13 Feb Link to this post

    Hi Ivan,

    This would be an expected behavior when running the application in debug mode. There is no way for the control to be aware what objects implement the interface. So, if you have manually defined the columns of the control with their DataMemberBinding pointing to a property of the object implementing the interface, the reported exception cannot be avoided. With this in mind, may I kindly ask you to check whether by any chance you have enabled the exceptions in VisualStudio?

    Regards,
    Stefan X1
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Ivan
    Ivan avatar
    46 posts
    Member since:
    Nov 2013

    Posted 14 Feb Link to this post

    Hi Stefan X1,

    thanks for your answer. We need to log the exceptions from our application. So these exceptions are saved in logs. I just want to reduce some logs like these 'expected exception' ;-)  I will try with release mode and hopefully these exception will not be saved any more.

     

    Regards,

    Ivan

  4. Ivan
    Ivan avatar
    46 posts
    Member since:
    Nov 2013

    Posted 14 Feb in reply to Stefan X1 Link to this post

    Hi Stefan X1,

    i just tried with release version. These exceptions are also triggered by RadGridView and saved in logs. The logger will be called with a FirstChanceException.

    AppDomain.CurrentDomain.FirstChanceException += FirstChanceException;

    It seems there is no way to avoid these exceptions without definition of columns in interface.

    Regards,

    Ivan

Back to Top