This is a migrated thread and some comments may be shown as answers.

Linq :Object reference not set to an instance of an object.

1 Answer 1586 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
john
Top achievements
Rank 1
john asked on 30 Aug 2011, 03:05 PM

Dim dbNutBackupModel As New NutBackupModel
         
            Dim Query = From listcust In ( _
(From listcust0 In dbNutBackupModel.Customers.AsEnumerable _
Group Join listbackup1 In dbNutBackupModel.Backups On New With {listcust0.CustomerID} Equals New With {listbackup1.CustomerID} Into listbackup1_join = Group _
From listbackup1 In listbackup1_join.DefaultIfEmpty() _
Where _
  (Not listbackup1.CustomerID = Nothing) _
Group New With {listcust0, listbackup1} By _
  listcust0.CustomerName, _
  listbackup1.CustomerID _
 Into glist = Group _
Select _
  CustomerName, _
  CustomerID = CType(CustomerID, Int32?), _
  Maxdate = CType(glist.Max(Function(p) p.listbackup1.EndTime), DateTime?)) _
) _
Group Join listbackup In ( _
((From backups In dbNutBackupModel.Backups _
Select _
  backups.CustomerID, _
  backups.Success, _
  backups.EndTime) _
.Distinct())) On New With {.Maxdate = listcust.Maxdate} Equals New With {.Maxdate = listbackup.EndTime} Into listbackup_join = Group _
From listbackup In listbackup_join.DefaultIfEmpty() _
Select _
 listcust.CustomerName, _
 listcust.CustomerID, _
 Maxdate = CType(listcust.Maxdate, DateTime?), _
 Success = CType(listbackup.Success, Boolean?)
            ' Dim ItemsSource As New ListViewItem
            'ItemsSource = Query
            rgdDashBoard.DataSource = Query


Here ,
I got this exception


Anonymously Hosted DynamicMethods Assembly


   at lambda_method(ExecutionScope , VB$AnonymousType_2`3 )
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`4.GetEnumerator()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<GroupJoinIterator>d__6a`4.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__31`3.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at NutBackupWeb.Dashboard.rgdDashBoard_NeedDataSource(Object source, GridNeedDataSourceEventArgs e) in E:\Projects\NutStor\liya\NutBackup\NutBackup\Web\Dashboard.aspx.vb:line 76

Please help me on this ..

Thanks and Regards


Mukesh

1 Answer, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 31 Aug 2011, 05:18 PM
Hi John,

 this is a bit hard to follow, but you have got a null reference somewhere, possibly in the lambda of the Max.
I propose to break this statement down by using ToList() in between to isolate the issue.

Best wishes,
Thomas
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

Tags
LINQ (LINQ specific questions)
Asked by
john
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Share this question
or