Getting System.Reflection.TargetException: 'Object does not match target type.' when binding the datasource to an OC of type Interface

Hi,

I have the following two classes:

GoogleEvent and Appointment. 

The both implement this interface:

 public interface IEvent
    {
        string WithWho { get; set; }
        string Subject { get; set; }

        string Details { get; }
         DateTime? ToDate { get; set; }
         DateTime? FromDate { get; set; }
         string ClientId { get; set; }
          Client client { get; }

          string Id { get; set; }
          Xamarin.Forms.Color PersonColour { get; }
    }



Now, I have an ObservableCollection:

public ObservableCollection<IEvent> AllEvents {get; set;}

I can add the items to this collection fine but when I load the page that contains SfSchedule, no event appears in the calendar!

Also, when forcefully setting the DataSource to the ObservableCollection again, it throws this error:





And the stacktrace:







9 Replies

SS SaiGanesh Sakthivel Syncfusion Team March 2, 2020 08:49 AM UTC

Hi Amir, 
 
Thank you for contacting synucfusion support. 
 
We check the reported query System.Reflection.TargetException: 'Object does not match target type from our end. We would like to inform you that the issue will occurs when the SfScheduleMapping is not implement while using Custom Appointment in the SfSchedule. 
 
Code Snippet 
<Syncfusion:SfSchedule x:Name="Schedule" ScheduleView="DayView" DataSource="{Binding Meetings}"> 
  <Syncfusion:SfSchedule.AppointmentMapping> 
    <Syncfusion:ScheduleAppointmentMapping  
          ColorMapping="Color" 
          EndTimeMapping="To" 
          StartTimeMapping="From" 
          SubjectMapping="EventName"/> 
  </Syncfusion:SfSchedule.AppointmentMapping> 
</Syncfusion:SfSchedule> 
 
Refer the following UG link, 
 
please let us know if you would require further assistance. 
 
Regards, 
SaiGanesh Sakthivel 



AH Amir H March 2, 2020 10:27 AM UTC

Hi,

I do have the appointment mapping already.  (Please see my code below).

This issue only happens when the DataSource is bound to an Observable Collection that is of type Interface. The Interface does have all those fields!




 <xForms:SfSchedule
                x:Name="scheduleDiary"
                Grid.Row="1"
                AllowAppointmentDrag="True"
                CellTapped="Schedule_OnCellTapped"
                DataSource="{Binding AllAppointments}"
                ScheduleView="MonthView"
                ShowAppointmentsInline="true">


                <xForms:SfSchedule.AppointmentMapping>
                    <xForms:ScheduleAppointmentMapping
                        ColorMapping="PersonColour"
                        EndTimeMapping="ToDate"
                        StartTimeMapping="FromDate"
                        SubjectMapping="Details" />
                </xForms:SfSchedule.AppointmentMapping>


                <xForms:SfSchedule.DragDropSettings>
                    <xForms:DragDropSettings
                        AllowNavigate="true"
                        AllowScroll="True"
                        ShowTimeIndicator="true">
                        <xForms:DragDropSettings.TimeIndicatorStyle>
                            <xForms:TimeIndicatorStyle
                                TextColor="GreenYellow"
                                TextFormat="hh:mm"
                                TextSize="13" />
                        </xForms:DragDropSettings.TimeIndicatorStyle>
                    </xForms:DragDropSettings>

                </xForms:SfSchedule.DragDropSettings>


                <xForms:SfSchedule.MonthViewSettings>
                    <xForms:MonthViewSettings AppointmentDisplayMode="Appointment" AppointmentIndicatorCount="20" />
                </xForms:SfSchedule.MonthViewSettings>
            </xForms:SfSchedule>


SS SaiGanesh Sakthivel Syncfusion Team March 3, 2020 08:45 AM UTC

Hi Amir, 
 
Thank you for the update. 
 
We check the reported query System.Reflection.TargetException: 'Object does not match target typefrom our end. We workedout on your Xaml file and also details provided from your end and we prepared the simple sample for your reference. We used the interface observableCollection objects to the DataSource.  
 
Code Snippet  
<Syncfusion:SfSchedule x:Name="Schedule" ScheduleView="MonthView"  
                               ShowAppointmentsInline="true"  
                               DataSource="{Binding AllEvents}"> 
            <Syncfusion:SfSchedule.AppointmentMapping> 
                <Syncfusion:ScheduleAppointmentMapping  
                ColorMapping="PersonColour" 
                EndTimeMapping="ToDate" 
                StartTimeMapping="FromDate" 
                SubjectMapping="Details" /> 
            </Syncfusion:SfSchedule.AppointmentMapping> 
            <Syncfusion:SfSchedule.MonthViewSettings> 
                <Syncfusion:MonthViewSettings AppointmentDisplayMode="Appointment"  
                                              AppointmentIndicatorCount="20" /> 
            </Syncfusion:SfSchedule.MonthViewSettings> 
</Syncfusion:SfSchedule> 
 
Sample Link : ScheduleDemo 
 
We hope this helps. Please let us know, if need any further assistance. 
 
Regards, 
SaiGanesh Sakthivel


AH Amir H March 3, 2020 10:40 PM UTC

Hi,

Did you even read my post?

I don't have a problem with using this control and binding it to an Observable Collection. 

The problem is when I bind the DataSource to an ObservableCollection that has 2 or more different types inside it (albeit all implementing the same interface)


SS SaiGanesh Sakthivel Syncfusion Team March 4, 2020 01:34 PM UTC

Hi Amir, 
 
Thank you for the update. 
 
We have checked the reported query System.Reflection.TargetExceptionfrom our end. We regret to let you know that Schedule uses same type of instance to process the appointment internally. Hence we would request you to use the same type of instance to set the DataSource. 
 
Please let us know, if need any further assistance. 
 
Regards, 
SaiGanesh Sakthivel 



AH Amir H March 4, 2020 01:36 PM UTC

Hi,

That's very bad if I cannot set the DataSource to an ObservableCollection of type Interface in SfSchedule! 

Could anything be done about it? Because I am doing the same in SfListView without a problem (The datasource of a listview is an OC of type interface that has 10 different types in it and it works perfectly fine)


SS SaiGanesh Sakthivel Syncfusion Team March 5, 2020 01:28 PM UTC

Hi Amir, 
 
Thank you for update. 
 
We have checked the reported issue System.Reflection.TargetException: 'Object does not match target type  from our end. We are currently working on it and update you further details on March 9, 2020. We appreciate your patience until then. 
Regards, 
SaiGanesh Sakthivel 



SS SaiGanesh Sakthivel Syncfusion Team March 9, 2020 12:57 PM UTC

Hi Amir, 
 
Sorry for the incoinvence. 
 
We have check the reported issue System.Reflection.TargetException: 'Object does not match target type  from our end. We are currently working on our source and we need time to finalize the use case with multiple references of same type. We will update the details in one business day (March 10, 2020). We appreciate your patience until then. 
  
Regards, 
SaiGanesh Sakthivel 



SS SaiGanesh Sakthivel Syncfusion Team March 10, 2020 01:30 PM UTC

Hi Amir,  
  
Thank you for contacting Syncfusion support.  
  
We have checked your requirement of “Binding the DataSource to the ObservableCollection that of different classes” in Schedule Xamarin.Forms. As of now, schedule non different classes of objects cannot be set with DataSource and we have already logged a feature request for the same. We will implement this feature in any of our upcoming releases.   
  
At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience until then.  
  
Thank you for requesting this feature and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts.  
   
We are closing this incident now. You can also communicate with us regarding the open features any time using our Feature Report page.   
  
We will prioritize the features every release based on the demands and we do not have an immediate plan to implement this feature since we committed with already planned work. So, this feature will be available in any of our upcoming releases.   
​  
Please upvote this feature to make this our priority. While this feature itself is important we will prioritize the features every release, based on the user demands. So, this feature will be available in any of our upcoming releases  
   
   
If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal and cast your vote to make it count.  
  
Regards, 
SaiGanesh Sakthivel 


Loader.
Up arrow icon