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

  • SEARCH
  • Home
  • 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 6589649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:12:05+00:00 2026-05-25T17:12:05+00:00

i am having a simple demo class like this… Employee public class Employee {

  • 0

i am having a simple demo class like this…

Employee

public class Employee
        {
            public string Name { get; set; }
            public string Email { get; set; }

        }

one more class AddressDetails

public class AddressDetails
        {
            public string Address1 { get; set; }
            public string City { get; set; }
            public string State { get; set; }
        }

one more EmpAdd

public class EmpAdd 
        {
            public ICollection<Employee> Employees { get; set; }
            public ICollection<AddressDetails> AddressDetails { get; set; }
        }

ok, when i am passing some values in class like this..

Employee newEmp = new Employee();
            newEmp.Email = "temp@gmail.com";
            newEmp.Name = "Judy";

            AddressDetails newAddress = new AddressDetails();
            newAddress.Address1 = "UK";
            newAddress.City = "London";
            newAddress.State = "England";

all works fine…

but when i am trying to add this two in EmpAdd it gives me error “Object reference not set to an instance” please help …this is just a dummy .. i have 7 entities in which i am facing the same problem….

EmpAdd emp = new EmpAdd();
            emp.Employee.Add(newEmp);
            emp.AddressDetails.Add(newAddress);
  • 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-05-25T17:12:06+00:00Added an answer on May 25, 2026 at 5:12 pm

    Your ICollection property is never initialized. The auto properties implement a field behind your property, but it still needs to be assigned to.
    I suggest making your property read-only (get rid of the set), implement the field behind it yourself, and initialize it on declaration:

    private List<Employee> _employees = new List<Employee>();
    
    public ICollection<Employee> Employees { 
        get
        {
            return _employees;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really need help on this one. I am having a simple login form
I've created this simple demo because I'm having some trouble making auto-sizing work in
Say you have the following object: public class Address { public String Line1 {
Just a simple question,having this: fftw_complex *H_cast; H_cast = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*M*N); what is the
I am having trouble doing this simple task of changing my input box color
I'm wondering if this is something somewhat simple, but I'm having a problem ONLY
I am having a simple issues with this example and getting the a is
I am having a simple code where i want to know when does onRestoreInstanceState
What are the options for having a simple blog, content management system that will
I am having a very simple requirement.I need the border on left and right

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.