-
-
Notifications
You must be signed in to change notification settings - Fork 92
Closed
Description
The following expressions compile successfully, but exceptions are thrown during execution of the resulting delegates. The first is the one i'd actually like to use, and the second is a failed attempt to circumvent the first.
class Foo {
public int? Prop { get; set; }
}
static void Main(string[] args) {
int int32Comparand = 1;
Expression<Func<Foo, bool>> a = foo => foo.Prop == int32Comparand;
var ac = a.CompileFast();
var ar1 = ac(new Foo { Prop = null }); // throws NullReferenceException
var ar2 = ac(new Foo { Prop = 1 }); // throws NullReferenceException
Expression<Func<Foo, bool>> b = foo => Nullable.Equals(foo.Prop, null);
var bc = b.CompileFast();
var br1 = bc(new Foo { Prop = null }); // throws AccessViolationException
}