ParameterExpression Parsing Results in InvalidOperationException

Sep 30, 2011 at 12:23 PM

I get this exception occasionally:

System.InvalidOperationException: variable 'd' of type 'BLAH' referenced from scope '', but it is not defined

I modified the code to do partial evaluation of the original lamda expression as an attempt to simplify what was sent over the wire. This seems to cause the exception more frequently (and I've noted the scope has changed to the outer class containing the original Expression<Func<T,bool>> (I have created a Specification<T> object that uses your custom serialization to set a backing string property, which is then deserialized on the server.

I understand a bit as to why it occurs. Several forum threads indicate that multiple parameter expressions "referring to the same parameter" can cause this. However, I see in the code that ParseParameterExpressionFromXml checks the dictionary for an existing expression. So, it would seem parameter expressions should be reused correctly. Do you have any ideas what might be going on?

Oct 6, 2011 at 3:22 PM

Nevermind. I was reusing a serializer across threads by mistake.