Unrelated Exception?

Jan 2, 2010 at 6:59 PM

I have an expression that is basically equivalent to the following:

t =>
	t.ContextPaymentCreditCard == null
		? null
		: t.CreditCards
			.Cast<ICreditCard>()
			.Where(cc => cc.CVS == t.ContextPaymentCreditCard.CVS &&
				     cc.ExpiryMM == t.ContextPaymentCreditCard.ExpiryMM &&
				     cc.ExpiryYY == t.ContextPaymentCreditCard.ExpiryYY &&
				     cc.Name == t.ContextPaymentCreditCard.Name &&
				     cc.Number == t.ContextPaymentCreditCard.Number)
			.FirstOrDefault()

When I comment out the Where clause or portions of the where clause it works.  However, for some combination of the conditional expressions it fails with the following error:

ExpressionRewriter:1312
Rewrite of System.Linq.Enumerable.ToList() or System.Linq.Enumerable.ToDictionary() not fully compatible. Cast result of call up to System.Collection.Generic.IList<> or System.Collection.Generic.IDictionary<,> before using in expression.

The inner exception is:

Expression of type 'System.Func`5[System.Collections.IEnumerable,System.String,System.Nullable`1[System.Int32],System.Nullable`1[System.Int32],Obtics.Values.IValueProvider`1[Pleasant.Erp.Accounting.Backend.ICreditCard]]' cannot be used for parameter of type 'System.Func`5[System.Collections.IEnumerable,System.String,System.Nullable`1[System.Int32],System.Nullable`1[System.Int32],Pleasant.Erp.Accounting.Backend.ICreditCard]' of method 'Pleasant.Erp.Accounting.Backend.ICreditCard SelectExt4[IEnumerable,String,Nullable`1,Nullable`1,ICreditCard](System.Object[], Int32, System.Func`5[System.Collections.IEnumerable,System.String,System.Nullable`1[System.Int32],System.Nullable`1[System.Int32],Pleasant.Erp.Accounting.Backend.ICreditCard])'

   at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodInfo method, ReadOnlyCollection`1& arguments)
   at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression[] arguments)
   at Obtics.Values.ExpressionRewriter.MakeUnlimitedConvertCall(Expression nextExp, Boolean cascading) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\Values\ExpressionRewriter.cs:line 513
   at Obtics.Values.ExpressionRewriter.MakeConvertCall(Expression nextExp, Boolean cascading) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\Values\ExpressionRewriter.cs:line 476
   at Obtics.Values.ExpressionRewriter.MapMethod(MethodInfo orgMethodCall_Method, MapInfo& mapping, IEnumerable`1 arguments, Type resultType) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\Values\ExpressionRewriter.cs:line 1229
   at Obtics.Values.ExpressionRewriter.VisitMethodCall(MethodCallExpression orgMethodCall) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\Values\ExpressionRewriter.cs:line 1140
   at Obtics.ExpressionVisitor.Visit(Expression exp) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\ExpressionVisitor.cs:line 73
   at Obtics.Values.ExpressionRewriter.Observe(Expression ex) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\Values\ExpressionRewriter.cs:line 588
   at Obtics.Values.ExpressionRewriter.MapMethodArguments(MapInfo mapping, IEnumerable`1 orgMethodCallArgs, IEnumerable`1 orgMethodCallArgTypes, Int32& mapIndex) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\Values\ExpressionRewriter.cs:line 661
   at Obtics.Values.ExpressionRewriter.VisitConditional(ConditionalExpression c) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\Values\ExpressionRewriter.cs:line 948
   at Obtics.ExpressionVisitor.Visit(Expression exp) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\ExpressionVisitor.cs:line 61
   at Obtics.Values.ExpressionRewriter.ObserveLambdaBody(LambdaExpression ex, ExpressionObserverObject rewriteMethodMap) in C:\Pleasant\ThirdParty\Obtics-1.0.13.0\Obtics\Values\ExpressionRewriter.cs:line 1304

I did try passing in a strongly typed list for CreditCards, but that failed in the same way... the cast was not necessary to break it.

It seems that the outer exception might not be related to the inner one.  Any ideas what might be going on here and how to work around it?

Coordinator
Jan 3, 2010 at 12:29 PM

Appeared there was a bug in the expression rewriter. Fixed in ChangeSet 33016.

Thanks for reporting the issue.

Jan 4, 2010 at 4:37 AM

Great!  Thanks for the fix.