Library version 5.1.1
.NET 4.6
SelfServicing
I have code that creates a RelationCollection, then serializes it, and then (sometime later) deserializes it and uses it in a call to collection.GetMulti. This worked fine with v5.0, but after upgrading to 5.1.1 it's crashing.
Code is something like this:
...
var relations = GetRelations(); // Creates a relation collection and sets it up
var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
var stream = new System.IO.MemoryStream();
formatter.Serialize(stream, relations);
stream.Seek(0, System.IO.SeekOrigin.Begin);
var relationsCopy = (IRelationCollection)formatter.Deserialize(stream);
collection.GetMulti(predicate, maximumRows, llblSort, relations, prefetchPath, includeFields,
maximumRows == 0 ? 0 : (startRowIndex / maximumRows + 1), maximumRows);
The exception is:
System.Web.HttpUnhandledException (0x80004005): Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at SD.LLBLGen.Pro.ORMSupportClasses.RelationCollection.ToQueryTextInternal(Boolean ansiJoins, String& nonAnsiWhereClause, String nonAnsiRootTableReference, String nonAnsiFieldSuffix)
at SD.LLBLGen.Pro.ORMSupportClasses.RelationCollection.ToQueryText()
at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IRetrievalQuery query, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified)
at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, DbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause)
at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, DbConnection connectionToUse, IPredicate selectFilter, Int32 rowsToSkip, Int32 rowsToTake, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause)
at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, DbConnection connectionToUse, IPredicate selectFilter, Int32 rowsToSkip, Int32 rowsToTake, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateSelectQueryForGetMulti(QueryParameters parameters, DbConnection connectionToUse)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAction(ITransaction containingTransaction, QueryParameters parameters)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetMulti(ITransaction containingTransaction, IEntityFactory entityFactoryToUse, QueryParameters parameters)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.PerformGetMulti(QueryParameters parameters)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.GetMulti(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, IPrefetchPath prefetchPathToUse, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
I compiled a debug version of 5.1.1, and the problem is near line 400:
foreach(var fcd in _fromClauseDirectives)
{
fcdsPerAlias.Add(fcd.Alias, fcd);
}
_fromClauseDirectives is null, because it's marked as NonSerialized, and not initialized when creating the RelationCollection via deserialization.