Nullable object must have a value exception after upgrading to 18.3.35

System.InvalidOperationException: Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Syncfusion.Blazor.Schedule.Internal.VerticalEvents`1.OnParametersSetAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

4 Replies 1 reply marked as answer

AK Alagumeena Kalaiselvan Syncfusion Team October 6, 2020 02:10 PM UTC

Hi Andrey, 

Greetings from Syncfusion support! 

We have checked the Scheduler “InvalidOperationException” issue and tried with the specified version 18.3.0.35 in various ways. But we regret to let you know that we could not reproduce this issue at our end. Could you please share your Razor page which used in your application? that will help to reproduce the issue and validate it. 
  
Also, we have prepared a sample for your reference which can be downloaded from the following link. 

Regards 
Alagumeena.K 



MA Mr Andrey Voronov October 7, 2020 09:48 AM UTC

Please use the following Index.razor to reproduce the issue: 

@page "/"

@using Syncfusion.Blazor.Schedule

<SfSchedule TValue="DbCateringMenuScheduleItem" Height="550px" @bind-SelectedDate="@CurrentDate" FirstDayOfWeek="1" StartHour="08:00" EndHour="20:00" DateFormat="dd/MM/yyyy" WorkDays="@(new int[] { 0, 1, 2, 3, 4, 5, 6 })">
<ScheduleWorkHours Start="08:00" End="20:00"></ScheduleWorkHours>
<ScheduleEventSettings DataSource="@DataSource" AllowAdding="false" AllowEditing="false" AllowDeleting="false"></ScheduleEventSettings>
<ScheduleTemplates>
<DateHeaderTemplate>
@{
var item = context as TemplateContext;
var date = item.Date;
var today = date.Date == DateTime.Today;
}
<div>
<div>
@date.DayOfWeek.ToString().Substring(0, 3)
</div>
<div>
@date.Day
</div>
</div>
</DateHeaderTemplate>
</ScheduleTemplates>
<ScheduleViews>
<ScheduleView Option="View.Week">
<EventTemplate>
@{
var item = context as DbCateringMenuScheduleItem;
<div>
@item.TemplateName
</div>
}
</EventTemplate>
</ScheduleView>
</ScheduleViews>
</SfSchedule>

@code{
DateTime CurrentDate = new DateTime(2020, 1, 31, 0, 0, 0);

List<DbCateringMenuScheduleItem> DataSource = new List<DbCateringMenuScheduleItem>();

protected override void OnInitialized()
{
DataSource = new List<DbCateringMenuScheduleItem>
{
new DbCateringMenuScheduleItem { TemplateName = "Init", StartTime = new DateTime(2020, 1, 31, 9, 30, 0) , EndTime = new DateTime(2020, 1, 31, 11, 0, 0) }
};
}

public class DbCateringMenuScheduleItem
{
public long? SiteMealId { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public long MenuMealId { get; set; }
public string MealName { get; set; }
public long MenuTemplateId { get; set; }
public string TemplateName { get; set; }
public int? Week { get; set; }
public string WeekDay { get; set; }
}
}



AK Alagumeena Kalaiselvan Syncfusion Team October 8, 2020 01:22 PM UTC

Hi Andrey, 

Thanks for sharing sample with us. 

We have investigated your sample code and could replicate the NullReference exception at our end when Id field is not mapped to the DataSource. Also, we considered this case as defect and logged bug report which can be tracked from the following link. 

We will include the fix for this issue in our upcoming patch release which is scheduled on mid of October 2020. 
 
Until then we suggest to define Id field to resolve your issue. Refer the below highlighted code for that. 

public class DbCateringMenuScheduleItem 
    { 
        public long? SiteMealId { get; set; } 
        public DateTime StartTime { get; set; } 
        public DateTime EndTime { get; set; } 
        public long MenuMealId { get; set; } 
        public string MealName { get; set; } 
        public long MenuTemplateId { get; set; } 
        public string TemplateName { get; set; } 
        public int? Week { get; set; } 
        public string WeekDay { get; set; } 
        public int Id { get; set; } 
    } 

Also, we have prepared a sample based on your shared razor page which can be downloaded from the below link. 
 
Note: Id field is mandatory in case of performing CRUD actions. 

Kindly get back to us, if you need further assistance. 

Regards 
Alagumeena.K  



NR Nevitha Ravi Syncfusion Team October 13, 2020 07:49 AM UTC

Hi Andrey. 

Thanks for being patience. 

The reported issue “Null exception throws when Id field is not mapped to DataSource” has been resolved in our latest version 18.3.40. Please upgrade your version to overcome the issue. 



Please get back to us if you have any queries. 

Regards, 
Nevitha 


Marked as answer
Loader.
Up arrow icon