- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Index was outside the bounds of the array
I have problem with this query
SELECT Transactions.PFNo, PortfolioData.FundType
FROM dbo.Transactions AS Transactions
LEFT OUTER JOIN
(SELECT PortfolioID, Type,ContractNo, FundType
FROM dbo.PortfolioData
) as PortfolioData
ON Transactions.PFNo = PortfolioData.PortfolioID
when rewrite this query in LINQ
var PortfolioDataMMKQ = from t in metaData.PortfolioData
select new
{
t.PortfolioID,
t.Type,
t.ContractNo,
t.FundType
};
var q = from transactions in metaData.Transactions
join portfoliodata in PortfolioDataMMKQ on transactions.PFNo.Value equals portfoliodata.PortfolioID into portfoliodata_join
from portfoliodata in portfoliodata_join.DefaultIfEmpty()
select new
{
transactions.PFNo,
portfoliodata.ContractNo,
portfoliodata.FundType
};
var xx = q.ToList();
It throw exception that "Index was outside the bounds of the array."
stackTrace
at SD.LLBLGen.Pro.LinqSupportClasses.ValueListProjectionDefinition.AddProjectionListToProjection(ProjectionListExpression toAdd, ITemplateGroupSpecificCreator frameworkElementCreator, IElementCreatorCore generatedCodeElementCreator, MappingTracker trackedMappings)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleProjectionExpression(ProjectionExpression 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)
at BNIS.AMS.BL.Report.TransactionDetail.GetData() in C:\Projects\AMS\Solution\BNIS.AMS.BL\Report\TransactionDetail.cs:line 101
at BNIS.AMS.Win.TestForm.btnMahmoud2_Click(Object sender, EventArgs e) in C:\Projects\AMS\Solution\BNIS.AMS.Win\TestForm.cs:line 67
at System.Windows.Forms.Control.OnClick(EventArgs e)
at ComponentFactory.Krypton.Toolkit.KryptonButton.OnClick(EventArgs e)
at ComponentFactory.Krypton.Toolkit.KryptonButton.b(Object A_0, MouseEventArgs A_1)
at ComponentFactory.Krypton.Toolkit.ButtonController.OnClick(MouseEventArgs e)
at ComponentFactory.Krypton.Toolkit.ButtonController.MouseUp(Control c, Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewManager.MouseUp(MouseEventArgs e, Point rawPt)
at ComponentFactory.Krypton.Toolkit.VisualControlBase.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at ComponentFactory.Krypton.Toolkit.VisualControlBase.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
using Adapter mode DBMS Sql2008 VS 2008Sp1 runtime file version 2.6.9.1106 2009-12-24
BTW.. when change the out put of query one "PortfolioDataMMKQ ", sometime it works
join portfoliodata in PortfolioDataMMKQ on transactions.PFNo.Value equals portfoliodata.PortfolioID into portfoliodata_join
Try not using "Value" in the linq query.
BTW.. when change the out put of query one "PortfolioDataMMKQ ", sometime it works
![]()
"out put"? "sometimes"? (sometimes it works and sometimes not?)
I can create similar queries. There is something we should know in order to reproduce the problem? (inheritance, special custom code?).
Try not using "Value" in the linq query.
I tried before and still throw the same exception !!
"out put"? "sometimes"? (sometimes it works and sometimes not?)
I can create similar queries. There is something we should know in order to reproduce the problem? (inheritance, special custom code?).
yes.. when change result columns it works sometimes like replace "portfoliodata.FundType" field with other field from same table.
No inheritance, No special custom code ?!!
Unfortunatly, I can't reproduce it.
The following is working fine for me against Northwind database:
var q1 = from o in metaData.Orders
select new
{
o.OrderId,
o.OrderDate,
o.CustomerId,
o.Freight
};
var q = from c in metaData.Customers
join o in q1 on c.CustomerId equals o.CustomerId into co
from o in co.DefaultIfEmpty()
select new
{
c.CompanyName,
c.City,
c.Country,
o.OrderDate,
o.Freight
};
Am I doing something differently?
We received it. Please next time, when the error happens in the query generation, we don't need a 5MB database .
We'll look into it. It's very strange why you experienced this as the code which produces the query is deterministic and both fields have the same type.
With the project you sent we could reproduce it indeed. Very strange, we'll look into it.
Strangely, the expression trees are the same:
1: (gives error)
value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource2`1[LLBLTest.DAL.EntityClasses.TransactionsEntity])
.GroupJoin(value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource2`1[LLBLTest.DAL.EntityClasses.PortfolioDataEntity])
.Select(t => new <>f__AnonymousType0`4(PortfolioId = t.PortfolioId, Type = t.Type,
ContractNo = t.ContractNo, FundType = t.FundType)),
transactions => transactions.Pfno, portfoliodata => Convert(portfoliodata.PortfolioId),
(transactions, portfoliodata_join) => new <>f__AnonymousType1`2(transactions = transactions,
portfoliodata_join = portfoliodata_join))
.SelectMany(<>h__TransparentIdentifier0 => <>h__TransparentIdentifier0.portfoliodata_join.DefaultIfEmpty(),
(<>h__TransparentIdentifier0, portfoliodata) => new <>f__AnonymousType2`3(
Pfno = <>h__TransparentIdentifier0.transactions.Pfno,
ContractNo = portfoliodata.ContractNo, FundType = portfoliodata.FundType))
2: (ok)
value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource2`1[LLBLTest.DAL.EntityClasses.TransactionsEntity])
.GroupJoin(value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource2`1[LLBLTest.DAL.EntityClasses.PortfolioDataEntity])
.Select(t => new <>f__AnonymousType3`4(PortfolioId = t.PortfolioId, Type = t.Type,
ContractNo = t.ContractNo, FundName = t.FundName)),
transactions => transactions.Pfno, portfoliodata => Convert(portfoliodata.PortfolioId),
(transactions, portfoliodata_join) => new <>f__AnonymousType1`2(transactions = transactions,
portfoliodata_join = portfoliodata_join))
.SelectMany(<>h__TransparentIdentifier2 => <>h__TransparentIdentifier2.portfoliodata_join.DefaultIfEmpty(),
(<>h__TransparentIdentifier2, portfoliodata) => new <>f__AnonymousType4`3(
Pfno = <>h__TransparentIdentifier2.transactions.Pfno,
ContractNo = portfoliodata.ContractNo, FundName = portfoliodata.FundName))
except for 1 name. I've re-generated the code which didn't solve it, so I'll now see why the index error occurs.
(edit) the issue occurs because the index in the resultset is set to the ordinal of the field in the sourceset. With FundName this is '5' which is in range of the list to return (61) but FundType this is '75', and thus outside the list to return. Both are thus wrong, but one gives an exception.
It's an obscure bug and we'll look into how to fix this.
(edit) this northwind query reproduces it:
[Test]
public void LeftJoinWithCustomProjectionIndexProblemTest()
{
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
LinqMetaData metaData = new LinqMetaData(adapter);
var q1 = from e in metaData.Employee
select new
{
e.EmployeeId,
e.FirstName,
e.LastName,
e.RegionId
};
var q = from o in metaData.Order
join e in q1 on o.EmployeeId equals e.EmployeeId into co
from e in co.DefaultIfEmpty()
select new
{
o.OrderId,
o.CustomerId,
e.RegionId,
e.EmployeeId
};
foreach(var v in q)
{
}
}
}
as 'RegionId' has a higher ordinal than Order has fields. The projection it crashes in is for the Join, so it's not used in the final query, but it should work of course.
We've fixed it. It was a wrong assigned of an index, as the index was used for the array the field was in (projection) while the code was using the index as the index of the set it was pulled from (which was of course wrong).
See the attached assembly which fixes your problem.
Frans.. I face the same problem in other query but this time exception thrown when adding where clause
var securityHistoryQ = from s0 in metaData.SecurityHistory
join m in
(
(from t in metaData.SecurityHistory
where
t.Date <= AsOfDate
group t by new
{
t.CompanyCode
} into g
select new
{
CompanyCode = g.Key.CompanyCode,
MaxDate = g.Max(p => p.Date)
}))
on new { CompanyCode = s0.CompanyCode, MaxDate = s0.Date }
equals new { CompanyCode = m.CompanyCode, MaxDate = m.MaxDate }
select new
{
CompanyCode = s0.CompanyCode,
s0.ClosePrice,
s0.HighPurchase
};
var q = from a in metaData.Transactions
join k in securityHistoryQ
on a.SecCode equals k.CompanyCode into k_join
from k in k_join.DefaultIfEmpty()
join j in
(
(from d in metaData.Transactions
where
d.TrxDate <= AsOfDate &&
d.TrxTypeNormal == true
group d by new
{
d.PFNo,
d.SecCode
} into g
select new
{
TrxNo = g.Max(p => p.TrxNo)
})
) on a.TrxNo equals j.TrxNo
// when uncomment, the exception will be thrown
//where
// a.PFNo == 1 &&
// (a.QuantityBalance != 0 ||
// a.BonusShare != 0 ||
// a.RightIssue != 0)
select new
{
PortfolioNo = a.PFNo,
SecurityEName = a.SecCode,
Type = 1,
a.QuantityBalance,
k.ClosePrice,
a.AmountBalanceYC,
a.AmountBalanceYCCurrency,
a.BonusShare,
a.RightIssue
};
and this is sql query
SELECT a.PFNo AS PortfolioNo, a.SecCode AS SecurityEName, 1 AS Type, a.QuantityBalance, k.ClosePrice, a.AmountBalanceYC, a.AmountBalanceYCCurrency, a.BonusShare, a.RightIssue,
FROM transactions a LEFT JOIN
(SELECT s.CompanyCode, s.ClosePrice, s.HighPurchase
FROM SecurityHistory s JOIN
(SELECT CompanyCode, MAX([Date]) AS MaxDate
FROM SecurityHistory
WHERE [Date] <= asOfDate
GROUP BY CompanyCode) m ON m.CompanyCode = s.CompanyCode AND m.MaxDate = s.[Date]) k ON a.SecCode = k.CompanyCode INNER JOIN
(SELECT MAX(d .TrxNo) AS TrxNo
FROM Transactions d
WHERE d .TrxDate <= asOfDate AND d .TrxTypeNormal = 1
GROUP BY d .PFNo, d .SecCode) j ON a.trxno = j.trxno
WHERE a.PFNo = 1 AND ((a.QuantityBalance <> 0) OR
(a.BonusShare <> 0) OR
(a.RightIssue <> 0))
The exact same exception? Please post the new exception + stacktrace.
Also, we cleaned up your test repro project already as the bug was fixed. So we don't have your test db / entities anymore
Otis wrote:
The exact same exception? Please post the new exception + stacktrace.
(edit) Index was outside the bounds of the array.
at SD.LLBLGen.Pro.LinqSupportClasses.ValueListProjectionDefinition.AddProjectionListToProjection(ProjectionListExpression toAdd, ITemplateGroupSpecificCreator frameworkElementCreator, IElementCreatorCore generatedCodeElementCreator, MappingTracker trackedMappings)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleProjectionExpression(ProjectionExpression 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.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.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleWhereExpression(WhereExpression 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.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)
at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression 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)
at BNIS.AMS.BL.Report.PortfolioPosition.GetDataTest(DateTime AsOfDate, Int32 PfNo) in C:\Projects\AMS\Solution\BNIS.AMS.BL\Report\PortfolioPosition.cs:line 377
at BNIS.AMS.Win.TestForm.btnMM1_Click(Object sender, EventArgs e) in C:\Projects\AMS\Solution\BNIS.AMS.Win\TestForm.cs:line 89
at System.Windows.Forms.Control.OnClick(EventArgs e)
at ComponentFactory.Krypton.Toolkit.KryptonButton.OnClick(EventArgs e)
at ComponentFactory.Krypton.Toolkit.KryptonButton.b(Object A_0, MouseEventArgs A_1)
at ComponentFactory.Krypton.Toolkit.ButtonController.OnClick(MouseEventArgs e)
at ComponentFactory.Krypton.Toolkit.ButtonController.MouseUp(Control c, Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
at ComponentFactory.Krypton.Toolkit.ViewManager.MouseUp(MouseEventArgs e, Point rawPt)
at ComponentFactory.Krypton.Toolkit.VisualControlBase.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at ComponentFactory.Krypton.Toolkit.VisualControlBase.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Otis wrote:
Also, we cleaned up your test repro project already as the bug was fixed. So we don't have your test db / entities anymore
Do you need to prepare test project??
Yes, if you could mail us again: - the .lgp file - some code which fetches the query which fails. This can be a console app.
We'll then generate the dal from the lgp file, use the latest builds of the runtime and check whether we can reproduce it. We don't need your database as the error occurs in the query production, so before the db is contacted.
mohamed wrote:
Yes. I sent test project to support AT llblgen DOT com this thim without (5 mb DataBase)
![]()
We received it. We'll look into it. (will be tomorrow before we have an answer though)
et voila
SELECT [LPA_L2].[PFNo] AS [PortfolioNo], [LPA_L2].[SecCode] AS [SecurityEName], @LO11 AS [LPFA_4],
[LPA_L2].[QuantityBalance], [LPA_L1].[ClosePrice], [LPA_L2].[AmountBalanceYC] AS [AmountBalanceYc],
[LPA_L2].[AmountBalanceYCCurrency] AS [AmountBalanceYccurrency], [LPA_L2].[BonusShare], [LPA_L2].[RightIssue]
FROM ((
(
SELECT [LPA_L6].[CompanyCode], [LPA_L6].[ClosePrice], [LPA_L6].[HighPurchase]
FROM ( (
SELECT [LPA_L7].[CompanyCode], [LPA_L7].[LPAV_] AS [MaxDate]
FROM (
SELECT [LPLA_3].[CompanyCode], MAX([LPLA_3].[Date]) AS [LPAV_]
FROM [LLBLTest].[dbo].[SecurityHistory] [LPLA_3]
WHERE ( ( ( [LPLA_3].[Date] <= @Date2)))
GROUP BY [LPLA_3].[CompanyCode]
) [LPA_L7]
) [LPA_L5] INNER JOIN [LLBLTest].[dbo].[SecurityHistory] [LPA_L6]
ON ( [LPA_L6].[CompanyCode] = [LPA_L5].[CompanyCode] AND [LPA_L6].[Date] = [LPA_L5].[MaxDate]))
) [LPA_L1] RIGHT JOIN [LLBLTest].[dbo].[Transactions] [LPA_L2]
ON [LPA_L2].[SecCode] = [LPA_L1].[CompanyCode])
INNER JOIN (
SELECT [LPA_L8].[LPAV_] AS [TrxNo]
FROM (
SELECT [LPLA_15].[PFNo] AS [Pfno], [LPLA_15].[SecCode], MAX([LPLA_15].[TrxNo]) AS [LPAV_]
FROM [LLBLTest].[dbo].[Transactions] [LPLA_15]
WHERE ( ( ( ( [LPLA_15].[TrxDate] <= @TrxDate3) AND ( [LPLA_15].[trxTypeNormal] = @TrxTypeNormal4))))
GROUP BY [LPLA_15].[PFNo], [LPLA_15].[SecCode]
) [LPA_L8]
) [LPA_L3] ON [LPA_L2].[TrxNo] = [LPA_L3].[TrxNo])
WHERE (((((([LPA_L2].[PFNo] = @Pfno5) AND ((([LPA_L2].[QuantityBalance] <> @QuantityBalance6)
OR ( [LPA_L2].[BonusShare] <> @BonusShare7)) OR ( [LPA_L2].[RightIssue] <> @RightIssue8)))))))
Will wrap up and build a release build for you which fixes this issue, once I've ran all the tests again.