Xamarin Forms System.Reflection.TargetInvocationException: 调用目标抛出异常

Xamarin Forms System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

我有一个每周包含 Syncfusion SfSchedule 的页面,当我尝试打开该页面时出现此错误:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation and the InnerException is: {System.ArgumentOutOfRangeException}. The App crashes on InitializeComponent(); line.

我正在从我的领域数据库中填充时间表的数据源。

这是 XAML 代码:

<ContentPage.Padding>
   <OnPlatform x:TypeArguments="Thickness"
             iOS="0, 20, 0, 0"
             Android="0"
             WinPhone="0" />
 </ContentPage.Padding>

<ContentPage.BindingContext>
  <ViewModels:ActivitiesViewModel/>
</ContentPage.BindingContext>

<WeeklySchedule:SfSchedule x:Name="activitiesWeeklySchedule"
                      BackgroundColor="White"
                      HorizontalOptions="FillAndExpand"
                      VerticalOptions="FillAndExpand"
                      ScheduleView="WeekView"
                      ShowAppointmentsInline="True">
</WeeklySchedule:SfSchedule>

这是背后的代码:

    Realm realm;
    ScheduleAppointmentCollection collection;
    public TeacherWeeklyView() {
        InitializeComponent();
        collection = new ScheduleAppointmentCollection() { };
        var config = new RealmConfiguration() { SchemaVersion = 3 };
        realm = Realm.GetInstance(config);
        var activities = realm.All<ActivitiesItems>();
        foreach (var item in activities) {
           System.Diagnostics.Debug.WriteLine(item.ActivitySubject);
           collection.Add(activity);
        }
        activitiesWeeklySchedule.DataSource = collection;
     }

这个问题是在需要更新 Syncfusion 包时出现的,所以我更新了它,但没有任何改变。

我修复了我删除了这部分代码:

<ContentPage.BindingContext>
   <ViewModels:ActivitiesViewModel/>
</ContentPage.BindingContext>