- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
LLBLGEN Error (Object Reference not set to an instance of an object)
Joined: 06-Sep-2012
Hi Guys,
I am getting this error and not sure why it's throwing this error. Are you able to shed any light? Below is the actual stack trace and also the function itself where this error is thrown:
Object reference not set to an instance of an object. Exception Type: System.NullReferenceException Source: SD.LLBLGen.Pro.ORMSupportClasses.NET20
Error Stack Trace: at SD.LLBLGen.Pro.ORMSupportClasses.EntityNameFinder.Traverse(IEntityFieldCore field)
at SD.LLBLGen.Pro.ORMSupportClasses.QueryApiObjectTraverser.TraverseExpressionOperand(IExpressionElement operand)
at SD.LLBLGen.Pro.ORMSupportClasses.QueryApiObjectTraverser.Traverse(IExpression objectToTraverse)
at SD.LLBLGen.Pro.ORMSupportClasses.QueryApiObjectTraverser.Traverse(Object objectToTraverse)
at SD.LLBLGen.Pro.ORMSupportClasses.QueryApiObjectTraverser.TraversePredicate(IPredicate objectToTraverse)
at SD.LLBLGen.Pro.ORMSupportClasses.QueryApiObjectTraverser.Traverse(IPredicate objectToTraverse)
at SD.LLBLGen.Pro.ORMSupportClasses.QueryApiObjectTraverser.Traverse(IPredicate objectToTraverse)
at SD.LLBLGen.Pro.ORMSupportClasses.QueryApiObjectTraverser.Traverse(IPredicate objectToTraverse)
at SD.LLBLGen.Pro.ORMSupportClasses.QueryApiObjectTraverser.Traverse(IPredicate objectToTraverse)
at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.DetermineInheritanceRelations(IEnumerable fields, IRelationCollection relations, IPredicate filter, IInheritanceInfoProvider inheritanceProvider, UniqueValueList`1 outerScopeAliases)
at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.AddInheritanceRelatedElementsToQueryElementsForDynamicList(InheritanceHierarchyType hierarchyType, IList fields, IPredicateExpression filter, IRelationCollection relations, IInheritanceInfoProvider infoProvider, String forEntityName)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateQueryFromElements(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAsDataTableAction(IEntityFields fieldsToReturn, DataTable tableToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Boolean allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, Int32 pageNumber, Int32 pageSize)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetMultiAsDataTable(IEntityFields fieldsToReturn, DataTable tableToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Boolean allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, Int32 pageNumber, Int32 pageSize)
at DSC.STARS.DAL.TypedViewClasses.SdsearchTypedView.Fill(Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IPredicate selectFilter, ITransaction transactionToUse, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) in C:\TFSSourceCode\DSC.STARS\Main\DSC.STARS.DAL\TypedViewClasses\SdsearchTypedView.vb:line 201
at DSC.STARS.DAL.TypedViewClasses.SdsearchTypedView.Fill(Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IPredicate selectFilter) in C:\TFSSourceCode\DSC.STARS\Main\DSC.STARS.DAL\TypedViewClasses\SdsearchTypedView.vb:line 149
at DSC.STARS.BAL.Referral.SearchReferral(PredicateExpression Filter, SortExpression Sort, Transaction Transaction) in C:\TFSSourceCode\DSC.STARS\Main\DSC.STARS.BAL\Referral.vb:line 385
at DSC.STARS.WEB.SDSearchInd.GetReferralData() in C:\TFSSourceCode\DSC.STARS\Main\DSC.STARS.WEB\SDSearchInd.aspx.vb:line 153
at DSC.STARS.WEB.SDSearchInd.dgReferrals_NeedDataSource(Object source, GridNeedDataSourceEventArgs e) in C:\TFSSourceCode\DSC.STARS\Main\DSC.STARS.WEB\SDSearchInd.aspx.vb:line 99
at Telerik.Web.UI.RadGrid.OnNeedDataSource(GridNeedDataSourceEventArgs e)
at Telerik.Web.UI.RadGrid.ObtainDataSource(GridRebindReason rebindReason, Boolean IsBoundUsingDataSourceId)
at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason)
at Telerik.Web.UI.RadGrid.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Error TargetSite: Traverse
Overridable Public Function Fill(maxNumberOfItemsToReturn As Long, sortClauses As ISortExpression, allowDuplicates As Boolean, selectFilter As IPredicate, transactionToUse As ITransaction, groupByClause As IGroupByCollection, pageNumber As Integer, pageSize As Integer) As Boolean Implements ITypedView.Fill
Dim fieldsInResultset As IEntityFields = GetFields()
' __LLBLGENPRO_USER_CODE_REGION_START AdditionalFields
' be sure To Call fieldsInResultset.Expand(number of New fields) first.
' __LLBLGENPRO_USER_CODE_REGION_END
Return DAOFactory.CreateTypedListDAO().GetMultiAsDataTable(fieldsInResultset, Me, maxNumberOfItemsToReturn, sortClauses, selectFilter, Nothing, allowDuplicates, groupByClause, transactionToUse, pageNumber, pageSize)
End Function
It seems that something is wrong with your predicate. Maybe you are including a field in the predicate that doesn't belong to the TypedView.
Please post the relevant code where you build the predicate and call the .Fill's typedView method. It should be on DSC.STARS.WEB.SDSearchInd.GetReferralData or DSC.STARS.BAL.Referral.SearchReferral.
Joined: 06-Sep-2012
This is the function where i am building the predicate:
Private Function GetSDDataBefore()
Dim dtType As DataTable
Dim udtTypeFilter As PredicateExpression = New PredicateExpression
If StrComp(ViewMode.ToLower, "followup") = 0 Then
'FOLLOWUP Session - StaffAssignmentId, CustomerReferralId and GroupSessionId values must all be present
GetFollowupSessionDetails()
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.StaffAssignmentId = StaffAssignmentID)
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.CustomerReferralId = CustomerReferralID)
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.GroupSessionId = GroupSessionID)
ElseIf StrComp(ViewMode.ToLower, "") = 0 Then
'INDIVIDUAL DELIVERY - StaffAssignmentId and CustomerReferralId values must be present, GroupSessionId must be NULL
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.StaffAssignmentId = StaffAssignmentID)
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.CustomerReferralId = CustomerReferralID)
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.GroupSessionId = Nothing)
ElseIf StrComp(ViewMode.ToLower, "customer") = 0 Then
'GROUP DELIVERY (Staff Hours) - CustomerReferralId and GroupSessionId values must be present, StaffAssignmentId must be NULL
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.CustomerReferralId = CustomerReferralID)
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.GroupSessionId = GroupSessionID)
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.StaffAssignmentId = Nothing)
Else
'GROUP DELIVERY (Staff Hours) - StaffAssignmentId and GroupSessionId values must be present, CustomerReferralId must be NULL
If StaffAssignmentID = Nothing Then
StaffAssignmentID = LastStaffAssignmentID
End If
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.StaffAssignmentId = StaffAssignmentID)
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.GroupSessionId = GroupSessionID)
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.CustomerReferralId = Nothing)
End If
udtTypeFilter.Add(ServiceDeliveryTypeDetailsFields.SeqNo >= ShownActivity_SeqNo)
Dim udtTypeSort As SD.LLBLGen.Pro.ORMSupportClasses.SortExpression = New SD.LLBLGen.Pro.ORMSupportClasses.SortExpression
udtTypeSort.Add(New SortClause(ServiceDeliveryTypeDetailsFields.SeqNo, SortOperator.Descending))
'Create the Typed View object that will be used to return records from the database.
dtType = BAL.ServiceDeliveryTypeDetail.Search(udtTypeFilter, udtTypeSort)
If Not dtType Is Nothing AndAlso _
dtType.Rows.Count > 0 Then
dgTypesBefore.Visible = True
Else
dgTypesBefore.Visible = False
End If
Return dtType
End Function
This is the funcation where it's calling the ServiceDeliveryTypedDetails View
Public Shared Function Search(ByVal Filter As PredicateExpression, _
Optional ByVal Sort As SortExpression = Nothing, _
Optional ByVal Transaction As Transaction = Nothing) As DataTable
'Create a filter that will be used to return the relevant records
'from the database.
Dim udtFilter As PredicateExpression = New PredicateExpression
If Not Filter Is Nothing Then
udtFilter = Filter
End If
If Sort Is Nothing Then
Sort = New SortExpression
Sort.Add(New SortClause(ServiceDeliveryTypeDetailsFields.CustomerReferralId, SortOperator.Ascending))
End If
'Execute the search and return the results.
Dim udtServiceDeliveryTypeDetails As New DAL.TypedViewClasses.ServiceDeliveryTypeDetailsTypedView
If Transaction Is Nothing Then
udtServiceDeliveryTypeDetails.Fill(0, Sort, True, Filter)
Else
udtServiceDeliveryTypeDetails.Fill(0, Sort, True, Filter, Transaction)
End If
Return udtServiceDeliveryTypeDetails
End Function
I wonder why those methods don't show up in your stack trace (GetSDDataBefore, Search). Please post the code for the following methods:
- **DSC.STARS.WEB.SDSearchInd.GetReferralData() ** (in C:\TFSSourceCode\DSC.STARS\Main\DSC.STARS.WEB\SDSearchInd.aspx.vb:line 153)
- **DSC.STARS.BAL.Referral.SearchReferral(PredicateExpression Filter, SortExpression Sort, Transaction Transaction) ** (in C:\TFSSourceCode\DSC.STARS\Main\DSC.STARS.BAL\Referral.vb:line 385)
Joined: 06-Sep-2012
Public Shared Function SearchReferral(ByVal Filter As PredicateExpression, _
ByVal Sort As SortExpression, _
Optional ByVal Transaction As Transaction = Nothing) As DataTable
'Create a filter that will be used to return the relevant Referral records
'from the database.
Dim udtFilter As PredicateExpression = New PredicateExpression
If Not Filter Is Nothing Then
udtFilter = Filter
End If
'Execute the search and return the results.
Dim udtReferral As New DAL.TypedViewClasses.SdsearchTypedView
If Transaction Is Nothing Then
udtReferral.Fill(0, Sort, True, Filter)
Else
udtReferral.Fill(0, Sort, True, Filter, Transaction)
End If
Return udtReferral
End Function
Private Function GetReferralData()
DAL.DaoClasses.CommonDaoBase.CommandTimeOut = Common.GetWebConfigSetting(WEB_CONFIG_COMMAND_TIMEOUT)
Dim dtReferral As DataTable
Dim udtReferralFilter As PredicateExpression = New PredicateExpression
udtReferralFilter.Add((SdsearchFields.DirectorateName = GetUserRoleDirectorate()) And (SdsearchFields.EmployeeNumber = CurrentUserEmployeeNumber()) And (SdsearchFields.GroupName = Nothing))
If ddlStatus.SelectedValue <> NO_FILTER Then
udtReferralFilter.Add(SdsearchFields.ReferralStatusId = ddlStatus.SelectedValue)
End If
If ddlCustomer.SelectedValue <> NO_FILTER Then
udtReferralFilter.Add(SdsearchFields.CustomerId = ddlCustomer.SelectedValue)
End If
If ddlTeam.SelectedValue <> NO_FILTER Then
udtReferralFilter.Add(SdsearchFields.TeamId = ddlTeam.SelectedValue)
End If
Dim udtReferralSort As SD.LLBLGen.Pro.ORMSupportClasses.SortExpression = New SD.LLBLGen.Pro.ORMSupportClasses.SortExpression
udtReferralSort.Add(New SortClause(SdsearchFields.CustomerName, SortOperator.Ascending))
'Create the Typed View object that will be used to return records from the database.
dtReferral = BAL.Referral.SearchReferral(udtReferralFilter, udtReferralSort)
If Not dtReferral Is Nothing AndAlso _
dtReferral.Rows.Count > 0 Then
dgReferrals.Visible = True
lblReferralsMessage.Text = "A total of " & dtReferral.Rows.Count & " Referral(s) found."
lblReferralsMessage.Visible = True
Else
dgReferrals.Visible = False
lblReferralsMessage.Text = "No Referrals found."
lblReferralsMessage.Visible = True
End If
Return dtReferral
End Function
The first pieces of code you gave have nothing to do with the problem. The last pieces of code you gave show the real methods you called, however there's 1 missing: GetUserRoleDirectorate()
the problem is that the crash happens in a visitor which visits the predicate and it finds an expression. However in your code there's no expression specified, so it can only be done in GetUserRoleDirectorate(): either it returns a field, or it returns a field with an expression.
Looking at our code, it seems the expression constructed has a null value for the field used in the expression. (so field == null). Please check GetUserRoleDirectorate() to see whether it can return null or that it constructs an expression which contains null for a field.
Btw, you don't have to check whether transaction is null for calling Fill(), the Fill() method will do that for you.
Joined: 01-Mar-2013
Hello vivek,
i had the same issue! Try to replace your 'NOTHING'-Statements in the predicates with System.DBNull.Value. That did it for me. Previously, i used 'NOTHING' too, in my predicates without any problem. But suddenly i got the Exception. No idea why the same predicate worked before... (BTW. using MS-SQL 2008 R2).
RitterSport wrote:
i had the same issue! Try to replace your 'NOTHING'-Statements in the predicates with System.DBNull.Value. That did it for me. Previously, i used 'NOTHING' too, in my predicates without any problem. But suddenly i got the Exception. No idea why the same predicate worked before... (BTW. using MS-SQL 2008 R2).
Thanks for the feedback. Actually yes, that is the correct way to filter null according to the documentation.