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 4101670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:43:38+00:00 2026-05-20T20:43:38+00:00

The following piece of code keeps giving me an error message of: Object reference

  • 0

The following piece of code keeps giving me an error message of:

Object reference not set to an instance of an object

var partsWithDefaults =
    from partsList1 in p
    join partsList2 in d on 
    new {   PartNo = partsList1.PartNumber, 
            Rev = partsList1.Revision }
    equals
    new {   PartNo = partsList2.PartNumber, 
            Rev = partsList2.Revision } into joinedLists
    from partDefaults in joinedLists.DefaultIfEmpty()
    select new Part()
    {
        PartNumber = partsList1.PartNumber,
        Revision = partsList1.Revision,
        Description = partsList1.Description,
        UoM = (partDefaults.UoM == null) ? "Null" : partDefaults.UoM,
        ABC = (partDefaults.ABC == null) ? "Null" : partDefaults.ABC            
    };

partsList1 is the master list which contains the PartNumber, Revision and Description fields. partsList2 contains the PartNumber and Revision fields (to join on) and also some supplemental fields (2 examples in code are UoM and ABC). There may not be an item in partsList2 for every item in partsList1 hence the need for a left outer join.

p and d are of type List<Part>.

How can this be fixed?

  • 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-20T20:43:39+00:00Added an answer on May 20, 2026 at 8:43 pm

    If joinedLists is empty, partDefaults will be null, so you can’t dereference it. Try this:

    UoM = partDefaults == null ? "Null" : partDefaults.UoM ?? "Null",
    ABC = partDefaults == null ? "Null" : partDefaults.ABC ?? "Null",
    

    (as the last two bits of your projection).

    Note that this copes with either partDefaults being null or the relevant property being null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following piece of code: declare @var bit = 0 select * from tableA
Consider the following piece of Java code. int N = 10; Object obj[] =
Following piece of code is from zipfile.py. self.fp.write(zinfo.FileHeader()) def FileHeader(self): header = struct.pack(structFileHeader, stringFileHeader,
The following piece of code is from u-boot: /* Initialize GOT pointer. ** Global
The following piece of code shows an Insert table dialog: Dialog d = WordApp.Dialogs[WdWordDialog.wdDialogTableInsertTable];
I have the following piece of code pattern: void M1(string s, string v) {
I have the following piece of code which replaces template markers such as %POST_TITLE%
I used the following piece of code in the service to debug the service
I have the following piece of code in Visual C++ 2005 : : class
I've got the following piece of code in an aspx webpage: Response.Redirect(/Someurl/); I also

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.