Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:58:39+00:00 2026-06-17T10:58:39+00:00

Possible Duplicate: What is a NullReferenceException in .NET? I have a Model (ASP.NET MVC

  • 0

Possible Duplicate:
What is a NullReferenceException in .NET?

I have a Model (ASP.NET MVC 4, C#) Called HoursOfOperation:

public class HoursOfOperation
{
    public List<DayTimes> Monday { get; set; }
    public List<DayTimes> Tuesday { get; set; }
    public List<DayTimes> Wednesday { get; set; }
    public List<DayTimes> Thursday { get; set; }
    public List<DayTimes> Friday { get; set; }
    public List<DayTimes> Saturday { get; set; }
    public List<DayTimes> Sunday { get; set; }
}

and a DayTimes

public class DayTimes
{
    public int Status { get; set; }
    public string From { get; set; }
    public string To { get; set; }
}

now I’m trying to add a new set to the Monday entity like below:

var _vm = new HoursOfOperation();

_vm.Monday.Add(new DayTimes{
      From = day.From.ToString(),
      To = day.To.ToString(),
      Status = (int)day.Status
});

as soon as the above statement is excecuted I’m getting a "Object reference not set to an instance of an object." Exception

Now I have checked and day.From.ToString() has a "08:00:00", day.To.ToString() has "09:30:00" and day.Status has a 1 at the time at which this statement throws the exception.

Any Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:58:40+00:00Added an answer on June 17, 2026 at 10:58 am

    That’s because Monday is not instantiated.

    You should do something like

    _vm.Monday = new List<DayTimes>();
    

    or alternatively, make all instantiations in HoursOfOperation‘s constructor like so:

    public HoursOfOperation()
    {
       Monday = new List<DayTimes>(),
       Tuesday = new List<DayTimes>(),
       Wednesday = new List<DayTimes>(),
       Thursday = new List<DayTimes>(),
       Friday = new List<DayTimes>(),
       Saturday = new List<DayTimes>(),
       Sunday = new List<DayTimes>()
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: File Upload ASP.NET MVC 3.0 I am trying to just print out
Possible Duplicate: How can I properly handle 404 in ASP.NET MVC? I've made the
Possible Duplicate: What is a NullReferenceException in .NET? I have a bunch of Labels
Possible Duplicate: What is a NullReferenceException in .NET? I've got a class Events that
Possible Duplicate: What is a NullReferenceException in .NET? Object reference not set to an
Possible Duplicate: .NET Enumeration allows comma in the last field public enum SubPackageBackupModes {
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: Does every Core Data Relationship have to have an Inverse? I have
Possible Duplicate: I have a nested data structure / JSON, how can I access

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.