3

Closed

Error when using parameters inside where clause

description

I was playing around with your demo project and substituted static string text by a variable, so for example:
 
       string test = "A";
        var res6 = from grp in groups
                   where grp.Name.StartsWith(test)  <-- NOTE: Here I replaced static text with test variable
                   select new { grp.Name, MemberCount = grp.Members.Length };
 
Now I get the error 'System.NullReferenceException was unhandled', the error occurs at case statement:
 
                   case "StartsWith":
                        {
                            ConstantExpression c = m.Arguments[0] as ConstantExpression;
                            sb.AppendFormat("{0}={1}*", GetFieldName(o.Member), c.Value); <--- EXCEPTION: on variable 'c'
                            break;
                        }
 
By the way thanks for this Linq class!! Excellent work!
 
Yours sincerely,
 
Evert Wiesenekker
Closed Jul 16, 2010 at 7:02 AM by bdesmet
The current release does what's requested. A future release will do proper closure capturing and be stricter about capturing outer state in order not to give the user the impression lots of operations get remoted.

comments

emargee wrote May 30, 2008 at 11:25 AM

Just wanted to point out I had found a solution to this (after a lot of hair tearing out as this is a frustrating bug)

You can delete the line : ConstantExpression c = m.Arguments[0] as ConstantExpression;

and then replace c.Value with : (string) Expression.Lambda(m.Arguments[0]).Compile().DynamicInvoke()

.. it then works fine ! (found after much searching in a comment at the bottom of here: http://weblogs.asp.net/okloeten/archive/2007/10/03/4327290.aspx)

Hope this helps people trying to use this !

[mRg]

pwalke wrote Jul 1, 2008 at 8:56 PM

I can confirm that this works. I'd be happy to merge these changes VIA team explorer in if I'm added as a developer to the project.

bdesmet wrote Jul 31, 2008 at 12:17 PM

This issue will be resolved in the 1.0.1 Refresh Release.

Thanks for the feedback,
-Bart