Error in CslaQueryProvider when getting max date from a businesslistbase?

Error in CslaQueryProvider when getting max date from a businesslistbase?

Old forum URL: forums.lhotka.net/forums/t/5576.aspx


shawndewet posted on Monday, October 13, 2008

Hi I'm using the following line of code to get the maximum date from a businesslistbase collection:

dtMaxJobStartDate = oJob.MyWipJobAllMatCollection.Max(Function(m) (m.SupplyDate))

But I get the following exception at runtime:

System.ArgumentException: The type or method has 2 generic parameter(s), but 1 generic argument(s) were provided. A generic argument must be provided for each generic parameter..

This is the Stack Trace:

System.RuntimeType.SanityCheckGenericArguments(Type[] genericArguments, Type[] genericParamters)
System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
Execute(Expression expression) in D:\PI Custom\CSLA\CSLA35\cslavb-3.5.1-080804\cslavb\Csla\Linq\CslaQueryProvider.vb: line 261
Execute[TResult](Expression expression) in D:\PI Custom\CSLA\CSLA35\cslavb-3.5.1-080804\cslavb\Csla\Linq\CslaQueryProvider.vb: line 198
TResult](IQueryable`1 source, Expression`1 selector)
TestSetJobStartAndEndDate(WipMaster& oJob, InvWarehouseCollection oATPQueriedInvWarehouseRecords) in ...

Can anyone advise where I should look? Am I doing something wrong?

AaronErickson replied on Tuesday, October 14, 2008

This might have been fixed with the latest CSLA patch. There was an issue where we were not carrying over the right number of generic parameters in our call to Queryable.Max inside the CslaQueryProvider, that has been fixed as of 3.5.2.

I have added the following unit test to my private build (should hit prod in a week), which passes:

[TestMethod]
public void TestMaxWithParameter()
{
CollectionExtendingIQueryable random = new CollectionExtendingIQueryable();

random.Add(new RandomThing(45));
random.Add(new RandomThing(65));

var max = random.Max(x => x.SomeVal);

Assert.IsTrue(max == 65);
}

This is C#, but as far as I know, it is roughly equivalent to what you are doing.

shawndewet replied on Monday, October 20, 2008

And so I immediately downloaded v3.5.2 and cleaned and rebuilt my solution, but the test still fails with the same error:

Test method TestUIP.SupportingServicesTest.TestUpdateJobDatesFromATPNonStockedJob threw exception:  System.ArgumentException: The type or method has 2 generic parameter(s), but 1 generic argument(s) were provided. A generic argument must be provided for each generic parameter..

The stack trace has changed slightly to indicate the file paths to the v3.5.2 csla files...

System.RuntimeType.SanityCheckGenericArguments(Type[] genericArguments, Type[] genericParamters)
System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
Execute(Expression expression) in D:\PI Custom\CSLA\CSLA35\cslavb-3.5.2-081009\cslavb\Csla\Linq\CslaQueryProvider.vb: line 261
Execute[TResult](Expression expression) in D:\PI Custom\CSLA\CSLA35\cslavb-3.5.2-081009\cslavb\Csla\Linq\CslaQueryProvider.vb: line 198
TResult](IQueryable`1 source, Expression`1 selector)
UIP.SupportingServices.SetJobStartAndEndDate(WipMaster& oJob, InvWarehouseCollection oATPQueriedInvWarehouseRecords) in d:\PI Custom\UIP\Services\UpdateJobDates.vb: line 65
UIP.SupportingServices.UpdateJobDeliveryDatesFromATPQuery(WipMasterCollection& oJobs, InvWarehouseCollection oATPQueriedInvWarehouseRecords, Boolean blnPostToSyspro) in d:\PI Custom\UIP\Services\UpdateJobDates.vb: line 16
TestUIP.SupportingServicesTest.TestUpdateJobDatesFromATPNonStockedJob() in D:\PI Custom\TestUIP\UpdateJobDateFromATPQueryTest.vb: line 88

 

Any other ideas? Is there perhaps something wrong with the line of code I'm using to extract the max date value?

AaronErickson replied on Monday, October 20, 2008

I will take a look at this first thing in the morning.  Wondering if VB (horror of horrors) is causing a difference.

Will also make double sure there isn't some other overload of Max involved here.

AaronErickson replied on Monday, October 20, 2008

Real quick question - SupplyDate does not happen to be Nullable, does it?

Not that it should matter, but I noticed that there are special nullable<T> overloads of Max that may be involved here.

AaronErickson replied on Tuesday, October 21, 2008

Ok, I was able to recreate the issue with a date. Found a subtle problem with the generic parameterizing in LINQ to CSLA. Issue is fixed in the latest bits for the CSLA 3.6 branch.

Copyright (c) Marimer LLC