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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:23:44+00:00 2026-05-27T05:23:44+00:00

The following code throws a NullReferenceException. If I filter user table using another column,

  • 0

The following code throws a NullReferenceException. If I filter user table using another column, exception is not throwed. DateTime type columns cause this exception.

using (MyDataContext dc = new MyDataContext())
    {
        var ids = dc.Users.Where(c => c.BirthDate < DateTime.Now.AddYears(-10)).Select(c => c.UserId);

        var list = (from c in dc.Users
                    where ids.Contains(c.UserId)
                    select c).ToList();
    }

Stack trace like this:

[NullReferenceException: Object reference not set to an instance of an object.]


System.Data.Linq.SqlClient.SqlFactory.Member(SqlExpression expr, MemberInfo member) +182
   System.Data.Linq.SqlClient.QueryConverter.VisitMemberAccess(MemberExpression ma) +260
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +939
   System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +1011
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1003
   System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitChangeType(Expression expression, Type type) +12
   System.Data.Linq.SqlClient.QueryConverter.VisitCast(UnaryExpression c) +117
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +619
   System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression b) +35
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +427
   System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression b) +35
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +427
   System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression sequence, LambdaExpression predicate) +125
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +3403
   System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +74
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1003
   System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression sequence, LambdaExpression selector) +17
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +1368
   System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +74
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1003
   System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitContains(Expression sequence, Expression value) +377
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +9129
   System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +74
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1003
   System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +18
   System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression sequence, LambdaExpression predicate) +125
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +3403
   System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc) +74
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1003
   System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node) +79
   System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations) +114
   System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +132
   System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +35
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +7667686
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +61
   lab_test.Page_Load(Object sender, EventArgs ee) in d:\Projeler\Kardelen\Kod\Kardelen.Web.UI\lab\test.aspx.cs:543
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Is anybody get this exception?

Thanks for response.

  • 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-27T05:23:44+00:00Added an answer on May 27, 2026 at 5:23 am

    If I filter user table using another column, exception is not throwed.
    DateTime type columns cause this exception.

    Assuming you mean this comparison: c.BirthDate < DateTime.Now.AddYears(-10)

    Most likely BirthDate is null. In case it is sufficient in your scenario to just skip those users, you can add a check to see whether it is null before doing the date comparison.

    As a sidenote, you should probably define DateTime.Now.AddYears(-10) once before calling Where to prevent it from being recalculated, and worse from the value changing over time.

    DateTime tenYearsAgo = DateTime.Now.AddYears(-10);
    var ids = dc.Users
        .Where(c => c.BirthDate != null && c.BirthDate < tenYearsAgo)
        .Select(c => c.UserId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Amazon AWS .NET SDK v1.2.1. The following code throws an exception
The following code throws an compile-time error like Cannot convert type 'string' to 'int'
The following code throws System.UriFormatException: var uri = new UriBuilder(ftp://user:pass#word@ftp.somewhere.com:21/fu/bar.zip); System.UriFormatException: Invalid URI: A
The following code public class GenericsTest2 { public static void main(String[] args) throws Exception
The following line of code throws NullReferenceException error When I check some checkboxes from
The following code throws an exception which I have no idea what goes wrong
The following code throws a StaleStateException exception when the Order.OrderItems property (an IList) is
The following code throws an exception terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_function_call>
The following code throws an ArrayStoreException at toArray() . Should not the compiler have
The following code throws an exception: <TreeView ItemsSource={Binding TreeRootInstance} x:Name=Htree ItemTemplate=CellTemplate SelectedItemChanged=HTree_OnSelectedItemChanged KeyDown=HTree_KeyDown> <TreeView.Resources>

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.