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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:21:06+00:00 2026-05-25T16:21:06+00:00

According to the answer given for the same question: How to check IEnumerable<DataRow> returns

  • 0

According to the answer given for the same question: How to check IEnumerable<DataRow> returns null or has any row? and most of the google results I found, you are suppose to use .Any() to verify that the collection contains at least one item.

However, in the following code the .Any() is throwing an “Object reference not set to an instance of an object” exception. Can someone point out what I am doing wrong?

DataSet navData = GetNavigationData();
bool linkFound = false;

if(!CommonLibrary.IsDataSetEmpty(navData))
{
  IEnumerable<DataRow> foundLinks = from link in navData.Tables[0].AsEnumerable()
                                    where link.Field<string>("URL").ToLower() == searchURL
                                    select link;

  linkFound = (foundLinks.Any());
}

The relevant stack trace showing that the exception is coming from the Any() call:

at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at MyMethod in MySource.cs:line 259
  • 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-25T16:21:06+00:00Added an answer on May 25, 2026 at 4:21 pm

    Your problem is not that Any() is the problem. Your problem is that a field you are trying to access in your query is most likely returning null.

    I’d check that navData is not null and Tables is not null and Tables[0] is not null. Any() uses deferred execution, so when you assign your query it won’t necessarily get processed until it is requested, which happens to be when Any() is called. Thus any problems with the query will not manifest until it is actually iterated over.

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

Sidebar

Related Questions

According to answers to that question: Which, if any, C++ compilers do tail-recursion optimization?
According to select name from system_privilege_map System has been granted: SELECT ANY TABLE ...and
According to the answer to this question , there is no way to effectively
According to the answers to this question, I cannot embed a file version in
jQuery: // ACCORDION $('.accordion .answer').hide(); // hide all $('.accordion .question').click(function(){ $('.accordion .answer').slideUp(); // hide
This question will undoubtedly be difficult to answer and ask in a way that
I have looked and searched for an answer for that question and I found
My answer for a recent question about GOTOs and tail recursion was phrased in
I'm implementing web application with JDO in Google App Engine. According to documentation ,
According to this paper differentiation works on data structures. According to this answer :

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.