Strange null reference issue

Status
Not open for further replies.

MattNorman

Well-known member
Joined
May 22, 2021
Messages
98
Programming Experience
1-3
I am getting an object null reference when setting a property on a newly created object:
C#:
ReportAgentCallSummaryFilterModel filtersReportPeriod = new ReportAgentCallSummaryFilterModel();
filtersReportPeriod.ReportInterval = FilterData.ReportInterval;

The exception is thrown on the second line and exception message is as follows:
System.NullReferenceException: Object reference not set to an instance of an object.
at ApexCCM.Models.ReportAgentCallSummaryFilterModel.set_ReportInterval(ReportIntervals value) in C:\Users\normanm\source\repos\New\ApexCCM\Models\ReportAgentCallSummaryFilterModel.cs:line 65
at ApexCCM.ViewModels.ReportOperationalInsightsViewModel.GetReportDataAgent() in C:\Users\normanm\source\repos\New\ApexCCM\ViewModels\ReportOperationalInsightsViewModel.cs:line 436
I am a little confused as inspecting both 'filtersReportPeriod' and 'FilterData' shows that neither are null.

I also added in to test lines that don't throw any exceptions as follows:

C#:
ReportAgentCallSummaryFilterModel filtersReportPeriod = new ReportAgentCallSummaryFilterModel();
ReportIntervals test = FilterData.ReportInterval;
ReportIntervals test2 = filtersReportPeriod.ReportInterval;
filtersReportPeriod.ReportInterval = FilterData.ReportInterval;

The property for the 'ReportAgentCallSummaryFilterModel' class is as follows:
C#:
private ReportIntervals reportInterval = ReportIntervals.Intraday;

public ReportIntervals ReportInterval
{
    get
    {
        return reportInterval;
    }
    set
    {
        reportInterval = value;
        ReportTimesRowHeight = ReportInterval == ReportIntervals.Intraday ? 35 : 0;
        AppDataStore.ReportOperationalInsightsFilterViewModelRef.GetDates();
    }
}
 
What does line 65 noted here:
C#:
C:\Users\normanm\source\repos\New\ApexCCM\Models\ReportAgentCallSummaryFilterModel.cs:line 65
correspond to in:
C#:
set
{
    reportInterval = value;
    ReportTimesRowHeight = ReportInterval == ReportIntervals.Intraday ? 35 : 0;
    AppDataStore.ReportOperationalInsightsFilterViewModelRef.GetDates();
}
If I had to guess, you likely have a race condition somewhere.
 
*sigh* you have a duplicate post. Closing this one.
 
Status
Not open for further replies.
Back
Top Bottom