- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Object reference not set to an instance of an object.
I'm Facing problem in executing this linq query that throw an exception
"Object reference not set to an instance of an object."
Full linq query
var metaData = DataAccess.LinqMetaDataFactory.Create();
var aQ = from t in metaData.TransactionsD
join t0 in metaData.Transactions on t.TrxNo equals t0.TrxNo
join t1 in metaData.TransactionTypeCodes on t0.TrxType.Value equals t1.Code
select new
{
t0.TrxDate,
t0.TrxTime,
TrxNo = t0.TrxNo,
TrxType = t0.TrxType,
t0.RefNo,
Code = t.RefCode,
t.Credit,
t.Debit,
t.Balance,
Remarks = t0.Details,
t.AccountNo,
PortfolioNo = t0.PFNo,
t.Currency,
t0.SecCode,
t0.Price,
t0.Quantity
};
var obQ = from a in metaData.Transactions
join b in metaData.TransactionsD on a.TrxNo equals b.TrxNo
join maxid in
(
(from a0 in metaData.Transactions
join b1 in metaData.TransactionsD on a0.TrxNo equals b1.TrxNo
join c in metaData.AccChart
on new { b1.AccountNo, b1.Currency }
equals new { AccountNo = c.Id, c.Currency }
where
a0.TrxDate < new DateTime( 2005,11,11)
group new { a0, b1 } by new
{
a0.PFNo,
b1.AccountNo
} into g
select new
{
ID = g.Max(p => p.b1.ID)
})) on b.ID equals maxid.ID
select new
{
a.PFNo,
b.AccountNo,
Balance = b.Balance
};
var q = from a in aQ
join b in metaData.TransactionTypeCodes on a.TrxType equals b.Code into b_join
from b in b_join.DefaultIfEmpty()
join e in metaData.PortfolioData on a.PortfolioNo.Value /*?? e.PortfolioID*/ equals e.PortfolioID into e_join
from ej in e_join.DefaultIfEmpty()
join c in metaData.AccChart
on new { AccountNo = a.AccountNo, a.Currency /*?? c.Currency*/ }
equals new { AccountNo = c.Id, c.Currency } into c_join
from c in c_join.DefaultIfEmpty()
join f in metaData.MarketInvestorGroup on ej.InvestorNo.Value equals f.GrpCode into f_join
from f in f_join.DefaultIfEmpty()
join g in metaData.CurrencyCodes on new { Currency = Convert.ToInt32(c.Currency) } equals new { Currency = g.Code }
join sd in metaData.SecurityData on new { SecCode = Convert.ToInt32(a.SecCode) } equals new { SecCode = sd.Code } into sd_join
from sd in sd_join.DefaultIfEmpty()
join ob in obQ
on new { PFNo = a.PortfolioNo, a.AccountNo }
equals new { ob.PFNo, ob.AccountNo } into ob_join
from ob in ob_join.DefaultIfEmpty()
select new
{
AccountNo = a.AccountNo ,
a.TrxDate,
a.TrxTime,
a.TrxNo,
Credit = a.Credit ?? 0,
Debit = a.Debit ?? 0,
PortfolioNo = a.PortfolioNo,
a.RefNo,
TrxType = a.TrxType,
TranType = b.Description,
AccountName = c.EName,
InvestorNo = ej.InvestorNo,
InvestorName = f.GrpName,
FundCurrency = g.ShortDesc,
OpeningBalance = ob.Balance ?? 0,
a.Price,
a.Quantity,
Ticker = sd.ShortEName,
ATicker = sd.ShortAName,
AccountNoOfDecimals = g.NoOfDecimals,
InvestorNameAr = f.GrpAName,
AccountNameAr = c.AName,
FundCurrencyAr = g.ShortADesc,
TranTypeAr = b.ADescription,
Parent = c.Parent,
Config53 = 724,
Config277 = "0",
MarketGroup = ej.InvestorNo,
Config288 = "0",
a.Remarks
};
var result = q.ToList();
source "SD.LLBLGen.Pro.LinqSupportClasses.NET35"
StackTrace
at SD.LLBLGen.Pro.LinqSupportClasses.LinqUtils.GetEntityNameFromType(Type entityType, IElementCreatorCore generatedCodeElementCreator)
at SD.LLBLGen.Pro.LinqSupportClasses.LinqUtils.GetEntityName(Object value, IElementCreatorCore generatedCodeElementCreator)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.CreateDynamicRelation(Object left, Object right, JoinHint joinType, String aliasLeft, String aliasRight, IPredicate onClause)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleGroupJoinExpression(GroupJoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleAndProcessJoinExpressionSide(SetExpression side, Expression sideSelector, Expression& handledSide, Expression& handledSideSelector, String& aliasSide)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleJoinExpression(JoinExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression)
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.Execute()
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
using Adapter mode DBMS Sql2008 VS 2008Sp1 runtime file version 2.6.10.224
Massive queries are unable to be debugged, so please do the following 1) create the tiniest query possible which still reproduces this problem. 2) make a repro case. 3) send us the repro case
Be absolutely sure the query is tiny, as massive queries have massive expression trees and are impossible to be debugged. Also without info about the entities it's also impossible, so include the .lgp file with your repro case.
The problem is caused by the fact that the left side of the join is aliased but the object the alias represents (e.g. an entity, join result etc.) isn't found in the alias - object cache, so it results to null, causing a problem when the join has to be created using LLBLGen Pro query api elements (dynamic relation). The root cause, as in many join issues, is the DefaultIfEmpty() construct, which re-aliases a part of a subtree elsewhere (why it is so crappy to handle it).
I think we've seen this before, though if I recall correctly (have to look it up in the bugtracker) it was too complicated to look into at that time (the repro query we found was massive, and debugging these are very hard, as expression handlers get called a lot of times, so it's hard to set breakpoints which give insight in where the problem is originating, as crashes like these are never caused by a bug in the code they crash in, but by a wrong conversion earlier, but when and where, that's the mystery to solve ).
I'll see if this is similar so we can fix the bug at the same time as the open issue. Regardless of that, it's odd this happens though. We'll try to find a solution for you.
edit: Reproducing query on northwind:
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
LinqMetaData metaData = new LinqMetaData(adapter);
var q1 = from od in metaData.OrderDetail
join o in metaData.Order on od.OrderId equals o.OrderId
select new { od.ProductId, o.CustomerId };
var q = from q1v in q1
join c in metaData.Customer on q1v.CustomerId equals c.CustomerId into c_join
from cj in c_join.DefaultIfEmpty()
select new { q1v.ProductId, cj.Country };
foreach(var v in q)
{
}
}
This isn't equal to the small set of edge cases currently crashing the linq provider.
mohamed wrote:
Yes.. It works.
I would like to appreciate and thank you for your rapid help
![]()
glad it's fixed!
I'll add a release build to this post. Just a sec.
(edit) Attached