- Home
- LLBLGen Pro
- Bugs & Issues
SetRelatedEntity System.IndexOutOfRangeException: Index was outside the bounds of the array.
Joined: 02-May-2012
Version: 3.5, January 17th, 2013 Runtime Version: 3.5.12.0317 Using Adapter Model, SQL Server 2008
I've been receiving the following error in a production environment and could use some help tracking down the issue. I haven't been able to reproduce it to provide too many details. Based on the stack trace it appears to be an issue with fetching a parent entity of the primary Entity for the query.(or maybe it's trying to add the entity to the collection of back-references) The application seems to work correctly for many hours or a few days, but then the page calling this method will go down and flood the logs with this error repeatedly. Restarting our website in IIS resolves the issue for a time.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.List`1.Add(T item)
at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.PerformAdd(T item) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\CollectionCore.cs:line 1275
at Gravitate.Domain.Adapter.EntityClasses.PricePublisherEntity.SetRelatedEntity(IEntityCore relatedEntity, String fieldName) in C:\Workspace\Gravitate\NGLEP - Prod\Gravitate.Domain.Adapter\DatabaseGeneric\EntityClasses\PricePublisherEntity.cs:line 372
at Gravitate.Domain.Adapter.EntityClasses.PriceInstrumentEntity.set_PricePublisher(PricePublisherEntity value) in C:\Workspace\Gravitate\NGLEP - Prod\Gravitate.Domain.Adapter\DatabaseGeneric\EntityClasses\PriceInstrumentEntity.cs:line 2599
at Gravitate.Domain.Adapter.EntityClasses.PriceInstrumentEntity.SetRelatedEntityProperty(String propertyName, IEntityCore entity) in C:\Workspace\Gravitate\NGLEP - Prod\Gravitate.Domain.Adapter\DatabaseGeneric\EntityClasses\PriceInstrumentEntity.cs:line 349
at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.MergeNormal(IEntityCollectionCore rootEntities, IPrefetchPathElementCore currentElement, Boolean rootEntitiesArePkSide) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\PersistenceCore.cs:line 850
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5146
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 2426
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProvider2.cs:line 142
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 261
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 624
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProQuery.cs:line 163
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Gravitate.WCF.PriceInstrument.LoadPriceInstruments(Int32[] locations, Int32[] strategies, IsActiveFilterType isActiveFilter) in C:\Workspace\Gravitate\NGLEP - Prod\Gravitate.WCF\PriceInstrument.svc.cs:line 32
The following error appears to have preceded the many instances of the above error.(although it was 15 minutes before the first)
System.ArgumentNullException: item can't be null
Parameter name: item
at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.Add(T item) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\CollectionCore.cs:line 349
at Gravitate.Domain.Adapter.EntityClasses.PriceInstrumentEntity.SetRelatedEntityProperty(String propertyName, IEntityCore entity) in C:\Workspace\Gravitate\NGLEP - Prod\Gravitate.Domain.Adapter\DatabaseGeneric\EntityClasses\PriceInstrumentEntity.cs:line 358
at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.MergeNormal(IEntityCollectionCore rootEntities, IPrefetchPathElementCore currentElement, Boolean rootEntitiesArePkSide) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\PersistenceCore.cs:line 872
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5146
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 2426
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProvider2.cs:line 142
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 261
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 624
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProQuery.cs:line 163
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Gravitate.WCF.PriceInstrument.LoadPriceInstruments(Int32[] locations, Int32[] strategies, IsActiveFilterType isActiveFilter) in C:\Workspace\Gravitate\NGLEP - Prod\Gravitate.WCF\PriceInstrument.svc.cs:line 32
at Gravitate.Website.Areas.Pricing.Controllers.PricingController.GetPrices(String Strategies, String Products) in C:\Workspace\Gravitate\NGLEP - Prod\Gravitate.Website\Areas\Pricing\Controllers\PricingController.cs:line 97
Any help would be much appreciated. Thanks.
As you said, the error suggest that something is messing the CollectionCore.PerformAdd code. Based on the line it happens, it's more weird because it's something like:
1274: _contents.Add( item );
1275: int index = (_contents.Count - 1); // crashes
It doesn't make sense that it crashes there, in any case it should crash before.
-
What is your runtime library version? (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7717)
-
Are you sharing a resource on that site/service? (like a collection, an entity, etc).
-
Please show us the code at Gravitate.WCF\PriceInstrument.svc.cs
-
Can you isolate the issue and reproduce it in a controlled environment? (I know it is hard in cases like this, but it would help if you can)
Runtime Version: 3.5.12.0317
This is the first release. please download the latest build of v3.5
Also, you say the designer is Version: 3.5, January 17th, 2013, how can you still use the old runtime build? Please make sure you use the latest runtime build, this bug has been fixed some time ago.
Joined: 02-May-2012
OK, will try the new version. We are also seeing the following error from the same query:
System.NullReferenceException: Object reference not set to an instance of an object.
at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.ProduceInitialDuplicateDetectionStores(IEntityCollectionCore collection, Dictionary`2& objectHashtable, Dictionary`2& objectHashes) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\PersistenceCore.cs:line 1128
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 580
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 4526
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5132
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 2426
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProvider2.cs:line 140
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 261
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 624
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProQuery.cs:line 162
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Gravitate.WCF.PriceInstrument.LoadPriceInstruments(Int32[] locations, Int32[] strategies, IsActiveFilterType isActiveFilter) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.WCF\PriceInstrument.svc.cs:line 32
at Gravitate.Website.Areas.Pricing.Controllers.PricingController.GetPrices(String Strategies, String Products) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.Website\Areas\Pricing\Controllers\PricingController.cs:line 97
Joined: 02-May-2012
Sorry, will try to circle back to those when I have a chance. I do not believe there are any shared entities involved. We're working on removing the prefetching involved in these errors for the mean time. Are you certain there was a fix that involved the code in the stack traces between the two versions? I was not able to find the current 3.5 download. I only saw how to buy 4.0 and how to request a license or download a trial. Could you point me in the right direction?
We have a frequent query that prefetches PricePublishers on PriceInstruments. We have a less-frequent query that prefetches PriceInstruments for a particular PricePublisher. We re-worked the first query to not do any prefetching and now the second is throwing the following , similar error.
System.NullReferenceException: Object reference not set to an instance of an object.
at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.ProduceInitialDuplicateDetectionStores(IEntityCollectionCore collection, Dictionary`2& objectHashtable, Dictionary`2& objectHashes) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\PersistenceCore.cs:line 1128
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 580
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 4526
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5132
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5005
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5148
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5005
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5148
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 2426
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProvider2.cs:line 140
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 261
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 583
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at Gravitate.Domain.Adapter.DAL.PricePublisherLoadManager.LoadPricePublisher(IQueryable`1 queryable, Nullable`1 pricePublisherType) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.Domain.Adapter.DAL\PricePublisherLoadManager.cs:line 12
at Gravitate.WCF.PricePublisher.LoadPricePublisher(Nullable`1 pricePublisherType) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.WCF\PricePublisher.svc.cs:line 31
at Gravitate.Website.Areas.Pricing.Controllers.PricingController.UpdateCell(String strategy, String product, String name, String uom, String columnIndex, String oldValue, String newValue) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.Website\Areas\Pricing\Controllers\PricingController.cs:line 222
I only saw how to buy 4.0 and how to request a license or download a trial. Could you point me in the right direction?
Go to LLBLGen.com, on the top right corner there is a "Customer Login" button. Click on it and sign in using your customer ID and pswd.
Then from the menu click on the "Customer Area", on the next page, you should find "Downloads" in the menu.
Joined: 02-May-2012
Do you have any details on this fix? I didn't see anything in the release notes that sounded related. The enum PK one sounded the closest, but I don't think we have any enum PK's unless I'm mistaken on what that means. Thanks.
Could you please give us some information to reproduce this? I can't find a way to reproduce it with the info you've given, sorry. The crash you run into is in a method which filters our duplicates, which uses hash codes based on the pk values. This is a method which is run through every fetch test we have (over a 1000) which all succeed, so I don't know what's specific to your case which makes it fall apart.
The code crashes on a line which only fails if the collection is null, but that never happens as the collection is part of a prefetchpath node which initializes the collection with a new instance, unless you called the prefetchpath element constructor and passed in a collection value which was null (there's no check on that in that code).
Joined: 02-May-2012
Hey Otis, I'll try to walk you through our original code that was failing. I re-wrote the code to not use prefetching, but instead to project to a custom entity using a linq select. This has resolved the issue in this case, but a couple of days ago we had a similar error on an unrelated query.(stack trace below)
System.NullReferenceException: Object reference not set to an instance of an object.
at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.ProduceInitialDuplicateDetectionStores(IEntityCollectionCore collection, Dictionary`2& objectHashtable, Dictionary`2& objectHashes) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\PersistenceCore.cs:line 1128
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 580
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 4526
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5132
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 2426
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProvider2.cs:line 140
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 261
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 624
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProQuery.cs:line 162
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Gravitate.WCF.MessageService.LoadMessagesByLabel(String[] tokens, Int32[] messageLabelIds, Int32[] credentialIds, Nullable`1 minDate, Nullable`1 maxDate) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.WCF\Message.svc.cs:line 48
at Gravitate.Website.Areas.Pricing.Controllers.PricingController.LoadMessages(String MessageTokens, String Label, String Users) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.Website\Areas\Pricing\Controllers\PricingController.cs:line 180
Failing here: (getPrices method of PricingController) This is called frequently via AJAX. PriceInstrumentEntity[] priceInstruments = priceInstrumentService.LoadPriceInstruments(strategies, products, IsActiveFilterType.ActiveOnly);
Service Method. This is not being called as a true WCF service. Instead it is configured in Windsor as such: The Controller is resolved using a MVC Windsor Controller factory. The controller is dependent upon a service called PriceInstrument. The PriceInstrument service is dependent upon IQueryable<PriceInstrument> (variable called queryable below). The IQueryable is constructed via a Windsor activator.(code shown farther down) The activator resolves a LinqMetaData instance which is dependent upon a DataAccessAdapter. All windsor registrations resolved are made using the Transient lifestyle. We were suspicious that an issue with Windsor reusing the same Adapter or something could be involved, but we confirmed that each request gets a different adapter and that the adapters are being disposed.
public PriceInstrumentEntity[] LoadPriceInstruments(int[] locations, int[] strategies, IsActiveFilterType isActiveFilter)
{
return queryable.LoadPriceInstruments(locations, strategies, isActiveFilter).ToArray();
}
DAL:
public static IQueryable<PriceInstrumentEntity> LoadPriceInstruments(this IQueryable<PriceInstrumentEntity> queryable, int[] strategies, int[] products, IsActiveFilterType isActiveFilter)
{
//int counterPartyId = new TradeEntryEntity().InternalCounterParty.CounterPartyId;
queryable = queryable.Prefetch(true, true, true, true, true, true);
if(strategies[0] != 0)
queryable = queryable.Where(strategy => strategies.Contains(strategy.BookId.Value));
if (products[0] != 0)
queryable = queryable.Where(product => products.Contains(product.ProductId.Value));
if (isActiveFilter != IsActiveFilterType.NoFilter)
queryable = queryable.Where(p => p.IsActive == (isActiveFilter == IsActiveFilterType.ActiveOnly) ? true : false);
queryable = queryable.Where(publisher =>
publisher.PricePublisher.PricePublisherTypeCvId == CodeSets.DALFacade.CodeSetFacade.Instance.PricePublisherType.PriceWorkbench.CodeValueId);
return queryable.OrderBy(strategy => strategy.Book.Name)
.OrderBy(product => product.Product.Name)
.OrderBy(desc => desc.Name);
}
Prefetch:
public static IQueryable<PriceInstrumentEntity> Prefetch(this IQueryable<PriceInstrumentEntity> queryable, bool prefetchBook, bool prefetchProduct, bool prefetchLocation,
bool prefetchUnitOfMeasure, bool prefetchCurvePoints, bool prefetchPricePublisher)
{
List<IPathEdge> pathEdges = new List<IPathEdge>();
if (prefetchBook) pathEdges.Add(PrefetchPathBook);
if(prefetchProduct) pathEdges.Add(PrefetchPathProduct);
if (prefetchLocation) pathEdges.Add(PrefetchPathLocation);
if(prefetchUnitOfMeasure) pathEdges.Add(PrefetchPathUnitOfMeasure);
if(prefetchCurvePoints) pathEdges.Add(PrefetchPathCurvePoints);
if(prefetchPricePublisher) pathEdges.Add(PrefetchPathPricePublisher);
if (pathEdges.Any()) queryable = queryable.WithPath(pathEdges.ToArray());
return queryable;
}
private static IPathEdge PrefetchPathBook = new PathEdge<BookEntity>(PriceInstrumentEntity.PrefetchPathBook);
private static IPathEdge PrefetchPathProduct = new PathEdge<ProductEntity>(PriceInstrumentEntity.PrefetchPathProduct);
private static IPathEdge PrefetchPathLocation = new PathEdge<LocationEntity>(PriceInstrumentEntity.PrefetchPathLocation);
private static IPathEdge PrefetchPathUnitOfMeasure = new PathEdge<UnitOfMeasureEntity>(PriceInstrumentEntity.PrefetchPathUnitOfMeasure);
private static IPathEdge PrefetchPathCurvePoints = new PathEdge<CurvePointEntity>(PriceInstrumentEntity.PrefetchPathCurvePoints,
new PathEdge<CurvePointPriceEntity>(CurvePointEntity.PrefetchPathCurvePointPrices),
new PathEdge<PeriodEntity>(CurvePointEntity.PrefetchPathPeriod));
private static IPathEdge PrefetchPathPricePublisher = new PathEdge<PricePublisherEntity>(PriceInstrumentEntity.PrefetchPathPricePublisher);
IQueryable Activator:
protected override object InternalCreate(Castle.MicroKernel.Context.CreationContext context)
{
Type entityType = context.RequestedType.GetGenericArguments()[0];
EntityType entityEnumType = (EntityType)Enum.Parse(typeof(EntityType), entityType.Name);
Type iQueryableType = typeof(IQueryable<>);
Type iQueryableGenericType = iQueryableType.MakeGenericType(entityType);
return kernel.Resolve<LinqMetaData>().GetQueryableForEntity((int)entityEnumType);
}
All entities involved use an identity, int column for their PK. Most are parent entities of PriceInstrument(Book, Product, Location, UnitOfMeasure). I'm attaching a diagram of the others.
Hopefully this helps some. Let me know what questions you have or what else you'd need. If you'd like, I could fire up a GoToMeeting and walk you through whatever you'd like to look at. I'm typically available from 8:30am - 5pm CDT.
To be clear, are you thinking that the DuplicateDetection issue is not resolved in the latest 3.5 runtime?
Filename | File size | Added on | Approval |
---|---|---|---|
Screen Shot 2013-06-06 at 1.13.14 PM.png | 89,717 | 06-Jun-2013 20:21.30 | Approved |
What LoadPriceInstruments has to do with the couple of methods at the end of the stack trace?
at Gravitate.WCF.MessageService.LoadMessagesByLabel(String[] tokens, Int32[] messageLabelIds, Int32[] credentialIds, Nullable
1 minDate, Nullable
1 maxDate) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.WCF\Message.svc.cs:line 48 at Gravitate.Website.Areas.Pricing.Controllers.PricingController.LoadMessages(String MessageTokens, String Label, String Users) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.Website\Areas\Pricing\Controllers\PricingController.cs:line 180
Joined: 02-May-2012
The code I provided was in regards to a previously posted stack trace.(see below) This is the error that was most frequently occurring. I posted the other stack trace to point out that a similar error is occurring on a different query.
System.NullReferenceException: Object reference not set to an instance of an object.
at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.ProduceInitialDuplicateDetectionStores(IEntityCollectionCore collection, Dictionary`2& objectHashtable, Dictionary`2& objectHashes) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Persistence\PersistenceCore.cs:line 1128
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 580
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 4526
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5132
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 2426
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProvider2.cs:line 140
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 261
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 624
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProQuery.cs:line 162
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Gravitate.WCF.PriceInstrument.LoadPriceInstruments(Int32[] locations, Int32[] strategies, IsActiveFilterType isActiveFilter) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.WCF\PriceInstrument.svc.cs:line 32
at Gravitate.Website.Areas.Pricing.Controllers.PricingController.GetPrices(String Strategies, String Products) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.Website\Areas\Pricing\Controllers\PricingController.cs:line 97
Joined: 02-May-2012
Also, I meant to re-emphasize the nature of the error. The code will run correctly without error for anywhere from hours to days even though these queries are very frequently executed. I have seen some one-off cases of the DuplicateDetection null reference error, but the real problem when it hits just spams our logs with hundreds of messages and every attempt to run the query fails. So, I just wanted to point that out that these queries run successfully hundreds, probably thousands of times before tanking. It makes me think it's getting into some odd state.
Also, I was thinking about attempting to download the source and debug the issue against our old code. I could possibly provide more information about what is null, etc.
private static IPathEdge PrefetchPathBook = new PathEdge<BookEntity>(PriceInstrumentEntity.PrefetchPathBook);
private static IPathEdge PrefetchPathProduct = new PathEdge<ProductEntity>(PriceInstrumentEntity.PrefetchPathProduct);
private static IPathEdge PrefetchPathLocation = new PathEdge<LocationEntity>(PriceInstrumentEntity.PrefetchPathLocation);
private static IPathEdge PrefetchPathUnitOfMeasure = new PathEdge<UnitOfMeasureEntity>(PriceInstrumentEntity.PrefetchPathUnitOfMeasure);
private static IPathEdge PrefetchPathCurvePoints = new PathEdge<CurvePointEntity>(PriceInstrumentEntity.PrefetchPathCurvePoints,
new PathEdge<CurvePointPriceEntity>(CurvePointEntity.PrefetchPathCurvePointPrices),
new PathEdge<PeriodEntity>(CurvePointEntity.PrefetchPathPeriod));
private static IPathEdge PrefetchPathPricePublisher = new PathEdge<PricePublisherEntity>(PriceInstrumentEntity.PrefetchPathPricePublisher);
Don't do this: you're sharing prefetch path nodes across queries, and likely across threads (as it's a WCF service). The node contains a collection into which the data is fetched. Always create the nodes directly into the query, don't pre-create them and then share them in queries.
I think this is the cause of your problems. Please remove these static variables and create them directly into the query. If you find it too verbose, please look into this extension for prefetch paths, which has a more fluent syntax and is less verbose: https://github.com/SolutionsDesign/LLBLGen.Linq.Prefetch
Joined: 02-May-2012
OK! Yeah, hopefully that's the issue.
I do like the prefetch setup where you don't have a lot of copy/paste redundancy. Reuse of prefetches makes sense since your query often has little to do with what you want to prefetch. Would it be OK to convert from static members to static methods or properties?
For example, change:
private static IPathEdge PrefetchPathBook = new PathEdge<BookEntity>(PriceInstrumentEntity.PrefetchPathBook);
To:
private static IPathEdge PrefetchPathBook{ get{ return new PathEdge<BookEntity>(PriceInstrumentEntity.PrefetchPathBook); } }
I'll try loading up the old code to see if I can reproduce the issue and verify this fixes it.
Thanks for your time. --Evan
Evan wrote:
OK! Yeah, hopefully that's the issue.
I do like the prefetch setup where you don't have a lot of copy/paste redundancy. Reuse of prefetches makes sense since your query often has little to do with what you want to prefetch. Would it be OK to convert from static members to static methods or properties?
Static methods are fine, as they'll re-create the objects each time. Properties are NOT fine, as they're the same as fields: they'll hold static state, which means you'll share the same object among multiple queries.
The property you have below is also OK, as it's effectively a static method which creates the object each time. As long as each time a new object is created, you're OK.
For example, change:
private static IPathEdge PrefetchPathBook = new PathEdge<BookEntity>(PriceInstrumentEntity.PrefetchPathBook);
To:
private static IPathEdge PrefetchPathBook{ get{ return new PathEdge<BookEntity>(PriceInstrumentEntity.PrefetchPathBook); } }
I'll try loading up the old code to see if I can reproduce the issue and verify this fixes it.
Thanks for your time. --Evan
Joined: 02-May-2012
Do you think this error would have the same cause or be due to something else?
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.Clear() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\CollectionCore.cs:line 390
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Boolean forceParameterizedPPath) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5153
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 2426
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProvider2.cs:line 142
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 261
at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute[TResult](Expression expression) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\LinqSupportClasses\LLBLGenProProviderBase.cs:line 583
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at Gravitate.WCF.PositionService.AdjustPositionForTradeEntry(TradeEntryEntity tradeEntry, String encryptedTradeEntryId) in C:\Workspace\Gravitate\NGLEP - Prod 4292\Gravitate.WCF\Position.svc.cs:line 204