Bug 7885 - Null Reference Exception in Expression.Lambda
Summary: Null Reference Exception in Expression.Lambda
Status: RESOLVED NORESPONSE
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-10-17 17:10 UTC by Pierce Boggan [MSFT]
Modified: 2013-12-05 18:36 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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 Developer Community or GitHub 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.

Related Links:
Status:
RESOLVED NORESPONSE

Description Pierce Boggan [MSFT] 2012-10-17 17:10:18 UTC
Works fine in the simulator (Debug & Release), but crashes on the device (which is an iPhone 4).

Code: 
#region Load Properties
var props = this.GetType()
.GetProperties()
.Where(p => p.GetSetMethod() != null && !p.GetCustomAttributes(true).Any(attr => attr is XmlIgnoreAttribute));

_setAllDefaultProperties = new List<Action>();

foreach (var prop in props)
{

var element = _xmlElement.Elements().FirstOrDefault(e => e.Name == prop.Name);
var setter = prop.GetSetMethod();

object value = element == null ? prop.GetValue(this, null) : XmlHelper.FromXml(element, prop.PropertyType);

var exp = Expression.Call( Expression.Constant(this), setter,
Expression.Constant(value));

var lambda = (Expression<Action>)Expression.Lambda(exp);

_setAllDefaultProperties.Add(lambda.Compile());

}
#endregion

Stacktrace: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Object reference not set to an instance of an object
at System.Linq.Expressions.Expression.CreateExpressionOf (System.Type type, System.Linq.Expressions.Expression body, System.Collections.ObjectModel.ReadOnlyCollection`1 parameters) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq.Expressions/Expression.cs:1573
at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, IEnumerable`1 parameters) [0x00033] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq.Expressions/Expression.cs:1588
at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.Linq.Expressions.ParameterExpression[] parameters) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq.Expressions/Expression.cs:1568
at System.Linq.Expressions.Expression.Lambda (System.Linq.Expressions.Expression body, System.Linq.Expressions.ParameterExpression[] parameters) [0x00025] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq.Expressions/Expression.cs:1547
at iGL.Engine.GameObject.InitFromXml () [0x000d7] in /Users/geodynamics/Desktop/srcnew/iGL.Engine/GameObjects/GameObject.cs:345
at iGL.Engine.GameObject..ctor (System.Xml.Linq.XElement xmlElement) [0x000c6] in /Users/geodynamics/Desktop/srcnew/iGL.Engine/GameObjects/GameObject.cs:224
at iGL.Engine.PerspectiveCamera..ctor (System.Xml.Linq.XElement element) [0x00000] in <filename unknown>:0
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00109] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:536
--- End of inner exception stack trace ---
Comment 1 Sebastien Pouliot 2012-10-17 18:41:40 UTC
It could be one (or many) of many things. It's impossible to be sure without a self-contained test case.

a. the code use reflection. If used on SDK types then the linker might have removed the code.

Note: the linker is enabled, by default, for device builds and disable (again by default) for simulator builds. It's easy to change that default if you want to confirm if it's the cause of the issue.

b. code generation. The simulator uses the JIT compiler and will allow it, the devices uses the AOT compiler and won't allow dynamic code generation.
Comment 2 PJ 2013-11-19 17:05:44 UTC
This bug has been in the NEEDINFO state with no changes for the last 90 days. Can we put this back into the NEW or CONFIRMED state, or are we still awaiting response?

If there is no change in the status of this bug over the next two weeks, this bug will be marked as NORESPONSE.
Comment 3 PJ 2013-12-05 18:36:10 UTC
This bug has not been changed from the NEEDINFO state since my previous comment, marking as RESOLVED NORESPONSE.

Please feel free to REOPEN this bug at any time if you are still experiencing the issue. Please add the requested information and set the bug back to the NEW (or CONFIRMED) state.