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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:03:04+00:00 2026-06-11T10:03:04+00:00

Alright, so I am currently trying to find all strings in a list that

  • 0

Alright, so I am currently trying to find all strings in a list that don’t exist in another list of strings. Here is what my code currently looks like:

var items = GetLiveItems(); // Returns List<string>
var currentItems = GetCurrentItems(); // Returns List<string>, Exception here

var rogueItems = items.Where(i => !currentItems.Contains(i)).ToList();

When I run the above code, I get a System.NullReferenceException on the second line. If I get rid of the 3rd line (items.Where…), the exception goes away. The two lists are rather large, first having 180k strings, second being 290k strings, but they are only 12 characters long each.

What could the issue be?

EDIT:

public static List<string> GetCurrentItems()
{
    var db = DatabaseFactory.CreateDatabase("DB");
    var command = db.GetStoredProcCommand("getItems");

    var items = new List<string>();

    using (var reader = SafeSqlReader(db.ExecuteReader(command)))
    {
        while (reader.Read()) items.Add(reader.GetString("name"));
    }

    return items;
}

EDIT:

So using the below code:

var rogueItems = items.Except(currentItems).ToList();

worked. Can anyone explain why my previous method didn’t? And the other suggested methods.

EDIT:

So, since I am having a hard time reproducing this in a project I can share with everyone to take a look, I want to provide this screen shot to prove I am not crazy.

Unexplained Exception

EDIT:

Here is a screen shot with the Except logic and you can see I successfully stepped over the line I got an exception before.

No exception here

  • 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-11T10:03:04+00:00Added an answer on June 11, 2026 at 10:03 am

    Try using the EXCEPT Linq method – http://code.msdn.microsoft.com/LINQ-Set-Operators-374f34fe rather than WHERE !Contains

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

Sidebar

Related Questions

Alright, here I am again trying to write code from scratch and I can't
Alright, so here's my problem. I'm trying to write a script in PHP that
Alright, I have a strange one here. We currently have a tools application that
Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright, here is my problem i'm trying to solve. I have an index page
Alright, currently I'm using GD to create a PNG image that logs a few
Alright, I'm trying to make it so that someone can vote for a server
Alright so here is what I am trying to do. Ones user uses short
I'm trying to figure out if it is alright to store passwords that are
Alright, second question on SO in one day. Looks like Windows programming makes me

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.