Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Unit Test (Passes on .NET fails on Mono 2.10.1):
public class TestLinqConstantExpression
void UseNonConstMemberVariable<T>(IEnumerable<T> data, Expression<Func<T, Boolean>> input)
var expression = (BinaryExpression)input.Body;
var memberExpression = (MemberExpression) expression.Right;
var constantExpression = (ConstantExpression) memberExpression.Expression;
var memberInfo = constantExpression.Type;
var fieldInfo = memberInfo.GetField(memberExpression.Member.Name);
public void MonoLinqSupportsNonConstMemberFieldInExpression()
var thisHasToBeNonConst = "a";
var items = new List<String>();
UseNonConstMemberVariable(items, item => item == thisHasToBeNonConst);
Mono JIT compiler version 2.10.1 (tarball)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
Notification: Thread + polling
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
This appears to be an abuse of LINQ on my part. In .NET constantExpression.Type just happens to be the same MethodInfo of memberExpression.Member. This does not appear to be the case in Mono.
The correct way to use LINQ in this scenario is:
var constantExpression = memberExpression.Expression as ConstantExpression;
var memberInfo = memberExpression.Member;
if (memberInfo is FieldInfo)
var value = ((FieldInfo)memberInfo).GetValue(constantExpression.Value);
Downgrading this to trivial.
The above works on mono 3.2.5 in the same as on .NET 4.5