This project is read-only.


Error when using parameters inside where clause


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'
By the way thanks for this Linq class!! Excellent work!
Yours sincerely,
Evert Wiesenekker
Closed Jul 16, 2010 at 8: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.


emargee wrote May 30, 2008 at 12:25 PM

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:

Hope this helps people trying to use this !


wrote Jul 1, 2008 at 9:45 PM

pwalke wrote Jul 1, 2008 at 9: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 1:17 PM

This issue will be resolved in the 1.0.1 Refresh Release.

Thanks for the feedback,

wrote Jul 16, 2010 at 8:01 AM

wrote Jul 16, 2010 at 8:02 AM

wrote Feb 14, 2013 at 7:56 PM

wrote May 16, 2013 at 10:18 AM