Bug 45141 - NRE from Interpreter LoopCompiler on iOS
Summary: NRE from Interpreter LoopCompiler on iOS
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-10-06 23:59 UTC by David Strickland
Modified: 2017-07-17 08:58 UTC (History)
8 users (show)

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


Attachments
Simple test case (9.57 KB, application/zip)
2016-10-12 08:46 UTC, Daniel Münch
Details
Testcase without AutoMapper (9.21 KB, application/zip)
2016-10-12 09:55 UTC, Daniel Münch
Details


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 FIXED

Description David Strickland 2016-10-06 23:59:56 UTC
Looks like this is a Mono iOS bug that shows up when using Automapper. Thought I'd log it here as well.



Using Auto mapper.

Trying to map an Ilist of Interfaces to an IList of implementations I am getting a Nullreference error. However I only receive this on iOS the same implementation works fine on Android. The error does not occur at the mapping the mapping goes through fine and the resulting collection appears to be fine. However after the event (onappearing) in which the map occurs completes only then does this error get raised. Presumably this is a Async method that doesnt complete till later a dispose or some other threading issue.

Downgrading to Automapper 4.2.1 resolves the error.

Good Luck - if this is half as hard to fix as it was to track down its going to be a pain for someone.

** Version
Using AutoMapper" version="5.1.1" targetFramework="portable45-net45+win8+wpa81" on iOS

** Error
System.NullReferenceException: Object reference not set to an instance of an object

** Code
var items = DataMapper.Mapper.Map, IList>(dailychallenges);

** Stack Trace
at Microsoft.Scripting.Interpreter.LoopCompiler.VisitVariable (System.Linq.Expressions.ParameterExpression node, Microsoft.Scripting.Ast.ExpressionAccess access) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LoopCompiler.cs:279
at Microsoft.Scripting.Interpreter.LoopCompiler.VisitParameter (System.Linq.Expressions.ParameterExpression node) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LoopCompiler.cs:271
at System.Linq.Expressions.ParameterExpression.Accept (System.Linq.Expressions.ExpressionVisitor visitor) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Ast/ParameterExpression.cs:118
at System.Linq.Expressions.ExpressionVisitor.Visit (System.Linq.Expressions.Expression node) [0x00006] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:57
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall (System.Linq.Expressions.MethodCallExpression node) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:414
at System.Linq.Expressions.MethodCallExpression.Accept (System.Linq.Expressions.ExpressionVisitor visitor) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Ast/MethodCallExpression.cs:106
at System.Linq.Expressions.ExpressionVisitor.Visit (System.Linq.Expressions.Expression node) [0x00006] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:57
at System.Linq.Expressions.ExpressionVisitor.VisitBinary (System.Linq.Expressions.BinaryExpression node) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:198
at Microsoft.Scripting.Interpreter.LoopCompiler.VisitBinary (System.Linq.Expressions.BinaryExpression node) [0x000b4] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LoopCompiler.cs:254
at System.Linq.Expressions.BinaryExpression.Accept (System.Linq.Expressions.ExpressionVisitor visitor) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Ast/BinaryExpression.cs:331
at System.Linq.Expressions.ExpressionVisitor.Visit (System.Linq.Expressions.Expression node) [0x00006] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:57
at System.Linq.Expressions.ExpressionVisitor.VisitConditional (System.Linq.Expressions.ConditionalExpression node) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:250
at System.Linq.Expressions.ConditionalExpression.Accept (System.Linq.Expressions.ExpressionVisitor visitor) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Ast/ConditionalExpression.cs:93
at System.Linq.Expressions.ExpressionVisitor.Visit (System.Linq.Expressions.Expression node) [0x00006] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:57
at System.Linq.Expressions.ExpressionVisitor.VisitLoop (System.Linq.Expressions.LoopExpression node) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:378
at System.Linq.Expressions.LoopExpression.Accept (System.Linq.Expressions.ExpressionVisitor visitor) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Scripting.Core/Ast/LoopExpression.cs:82
at System.Linq.Expressions.ExpressionVisitor.Visit (System.Linq.Expressions.Expression node) [0x00006] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/System.Core/Microsoft/Scripting/Ast/ExpressionVisitor.cs:57
at Microsoft.Scripting.Interpreter.LoopCompiler.CreateDelegate () [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LoopCompiler.cs:82
at Microsoft.Scripting.Interpreter.EnterLoopInstruction.Compile (System.Object frameObj) [0x00074] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ControlFlowInstructions.cs:601
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x0000e] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1304
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x0008d] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:957
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:904
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x0002a] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1281
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00096] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:854
at ObjCRuntime.Runtime.ThreadPoolDispatcher (System.Func`1[TResult] callback) [0x00006] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:238
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x0000c] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1206


Automapper Bug Report: https://github.com/AutoMapper/AutoMapper/issues/1682#issuecomment-250436937

Comment from that thread.
"What happens is that the interpreter compiles the expression after a given number of executions. So a repro should be easy to make, just run the list mapping inside a never-ending loop and wait for it to crash. After that, report it to the Mono team and see if they can help. A workaround is to set the compilation threshold to int.MaxValue, but I don't know if/how you can do that."
Comment 1 Timothy Risi 2016-10-07 01:02:25 UTC
Hello,

Could you please provide a test case for us to reproduce error?

Thanks!
Comment 2 Daniel Münch 2016-10-12 08:46:57 UTC
Created attachment 17992 [details]
Simple test case
Comment 3 Daniel Münch 2016-10-12 08:49:41 UTC
I just added a simple test case. Run it in the Simulator. When looking at the application output you'll never see then "Done" which should be printed right before the "return true;" in FinishedLaunching. To see the actual Exception the only way I found was to restart the application in Xamarin Studio. Only then you'll be able to see the stack trace in the application output window.
Comment 4 Daniel Münch 2016-10-12 09:55:48 UTC
Created attachment 17994 [details]
Testcase without AutoMapper

The issue can be reproduced without AutoMapper like mentioned in the AutoMapper issue.
Comment 5 Daniel Münch 2016-10-12 12:37:04 UTC
Given the reproduction without AutoMapper the issue becomes apparent: If the body of the Loop-Expression isn't a block, the HashSet _loopLocals never gets initialized, resulting in the NullReferenceException at https://github.com/IronLanguages/dlr/blob/bc67c0aa07f9170d6a4f80d54a6e5acc6cbdf2eb/Src/Microsoft.Dynamic/Interpreter/LoopCompiler.cs#L279-L282
Comment 6 Daniel Münch 2016-10-12 15:12:11 UTC
Possible solution here: https://github.com/mono/mono/pull/3759
Comment 7 Marek Safar 2016-12-14 15:21:37 UTC
.
Comment 8 Marek Safar 2016-12-19 21:43:13 UTC
Fixed in mono master
Comment 9 srinath.ganguri 2017-03-15 22:26:36 UTC
Hey Marek,

Can you please provide details on what Xamarin Release Cycle contain this bug fix?
Comment 10 Marek Safar 2017-03-23 09:54:11 UTC
It is included in dev-15.2 which should be in preview next month