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

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

3 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 08 Feb 2017, 08:28 PM

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

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 13 Feb 2017, 02:38 PM
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.
0
Ivan
Top achievements
Rank 1
answered on 14 Feb 2017, 08:49 AM

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

0
Ivan
Top achievements
Rank 1
answered on 14 Feb 2017, 12:37 PM

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

Tags
GridView
Asked by
Ivan
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Ivan
Top achievements
Rank 1
Share this question
or