Exception: 'Value cannot be null. Parameter name: key'

Posts   
 
    
Saulius
User
Posts: 9
Joined: 23-Mar-2018
# Posted on: 27-Mar-2018 11:01:23   

I am migrating project from LLBLGen version 4.1 to 5.3. The query that worked in 4.1 fails in 5.3. We use SQL Server 2016. Tested with LLBLGen 5.3.4 and 5.3.5

This is an example of code where I can reproduce this error (real query is too big and complex to copy here):

    class TestData
    {
        public int TestId { get; set; }
        public string TestText { get; set; }
    }

    void Test()
    {
        var names = new List<string> { "John", null };

        var testDataQuery = from person in personRepository.CreateQuery()
                     select new TestData
                     {
                         TestId = person.Id,
                         TestText = person.FirstName
                     };

        var query = from testData in testDataQuery
                    where names.Contains(testData.TestText)
                    select new 
                    {
                        Id = testData.TestId
                    };

        // EXCEPTION IS THROWN AT THIS LINE:
        var queryResult = query.ToList();
    }

Following SQL query is generated when we use v4.1:

SELECT [LPA_L1].[TestId] AS [Id] FROM (SELECT [LPLA_1].[Id] AS [TestId], [LPLA_1].[FirstName] AS [TestText] FROM [Person] [LPLA_1]) [LPA_L1] WHERE [LPA_L1].[TestText] IN ('John', NULL)

Following exception is thrown when we use v5.3:

System.ArgumentNullException: 'Value cannot be null. Parameter name: key'

Stacktrace:

at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value) at SD.LLBLGen.Pro.ORMSupportClasses.DbProviderFactoryInfo.SetParameterType(DbParameter parameter, String parameterType) at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.SetParameterType(DbParameter parameter, String parameterType) at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameterInstance(String parameterType) at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameterInstance(String parameterType, ParameterDirection direction, Object value) at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameterInstance(String parameterType, Object value) at SD.LLBLGen.Pro.ORMSupportClasses.DbSpecificCreatorBase.CreateParameter(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, ParameterDirection direction, Object valueToSet) at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareRangePredicate.ToQueryText(Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Boolean inHavingClause) at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText() at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.AppendWhereClause(IPredicate filter, QueryFragments destination, IQuery query) 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(IEntityFields selectList, DbConnection connectionToUse, IPredicate selectFilter, Int32 rowsToSkip, Int32 rowsToTake, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateQueryFromElements(ITransaction transactionToUse, QueryParameters parameters) at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetAsProjection(List1 valueProjectors, IGeneralDataProjector projector, ITransaction transactionToUse, QueryParameters parameters) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider.ExecuteValueListProjection(QueryExpression toExecute) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression, Type typeForPostProcessing) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.PerformExecute(Expression expression, Type resultType) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery1.Execute() at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 27-Mar-2018 19:18:00   

Strange that that works in v4.1 btw, as I presume the 'null' in the list of names is the problem here. If you specify a value instead of null, it works OK? (this to our understanding of where the core of the problem is located)

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Mar-2018 14:03:58   

reproduced

(edit) Fixed in v5.3.5 hotfix build available in an hour.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Mar-2018 16:03:23   

Now available.

Frans Bouma | Lead developer LLBLGen Pro
Saulius
User
Posts: 9
Joined: 23-Mar-2018
# Posted on: 29-Mar-2018 08:47:15   

Thank you for such quick fix. It works now correctly.