Bug 12586 - Dictionary<string, List<string>> crashes on iPhone
Summary: Dictionary<string, List<string>> crashes on iPhone
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-06-06 20:26 UTC by Dylan
Modified: 2013-11-20 05:51 UTC (History)
3 users (show)

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:

Description Dylan 2013-06-06 20:26:21 UTC
I know there are limitations with dictionaries in MonoTouch with value types. However I am experiencing a crash with a dictionary containing strings. 

I receive a Dictionary<string, List<string>> from a servicestack web service call. In debug mode I can see there is valid data being retrieved so it's not a web service thing. 

Then I pass this dictionary through to the UI which needs to process it. On the phone, this is where things break.

Callback code from the webservice looks as follows (where MakesAndModels is the dictionary):
private void HandleSearchCriteriaDownloaded(bool success, VehicleSearchCriteriaResponse criteria)
   InvokeOnMainThread()=> {
         var carMakes = criteria.MakesAndModels.Select(kv=>kv.Key); // crash

List<string> carMakes = criteria.MakesAndModels.Select(kv=>kv.Key).ToList(); // also crashes

Crash log:

	Unhandled Exception:
	0   SeritiUI                            0x0120e9ab SeritiUI + 18930091
	1   SeritiUI                            0x0120f589 SeritiUI + 18933129
	2   SeritiUI                            0x0120fb6d SeritiUI + 18934637
	3   SeritiUI                            0x0124b1f1 SeritiUI + 19177969
	4   SeritiUI                            0x00d29370 SeritiUI + 13796208
	at System.Linq.Enumerable.Select<System.Collections.Generic.KeyValuePair`2<string, System.Collections.Generic.List`1<string>>, string> (System.Collections.Generic.IEnumerable`1<System.Collections.Generic.KeyValuePair`2<string, System.Collections.Generic.List`1<string>>>,System.Func`2<System.Collections.Generic.KeyValuePair`2<string, System.Collections.Generic.List`1<string>>, string>) <0x00014>
	at Seriti.UI.CarSearchScreen/<HandleSearchCriteriaDownloaded>c__AnonStorey8.<>m__1A () <0x000e8>
	at MonoTouch.Foundation.NSActionDispatcher.Apply () <0x00014>
	at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000c8>
	9   SeritiUI                            0x011c82c3 SeritiUI + 18641603
	10  SeritiUI                            0x01241c6b SeritiUI + 19139691
	11  SeritiUI                            0x011a3f6f SeritiUI + 18493295
	12  Foundation                          0x326760f5 <redacted> + 460
	13  CoreFoundation                      0x31d34683 <redacted> + 14
	14  CoreFoundation                      0x31d33ee9 <redacted> + 212
	15  CoreFoundation                      0x31d32cb7 <redacted> + 646
	16  CoreFoundation                      0x31ca5ebd CFRunLoopRunSpecific + 356
	17  CoreFoundation                      0x31ca5d49 CFRunLoopRunInMode + 104
	18  GraphicsServices                    0x3587e2eb GSEventRunModal + 74
	19  UIKit                               0x33bbb301 UIApplicationMain + 1120
	at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0x000f0>
	at Seriti.UI.Application.Main (string[]) <0x00018>
	at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000c8>
	23  SeritiUI                            0x011c82c3 SeritiUI + 18641603
	24  SeritiUI                            0x01241c6b SeritiUI + 19139691
	25  SeritiUI                            0x01244b17 SeritiUI + 19151639
	26  SeritiUI                            0x01244d6b SeritiUI + 19152235
	27  SeritiUI                            0x011e3d1f SeritiUI + 18754847
	28  SeritiUI                            0x01298a4c SeritiUI + 19495500
	29  libdyld.dylib                       0x39ebeb20 <redacted> + 0

	Parameter name: source (System.ArgumentNullException)
	  at System.Linq.Check.SourceAndSelector (System.Object source, System.Object selector) [0x00000] in <filename unknown>:0 
	  at System.Linq.Enumerable.Select[KeyValuePair`2,String] (IEnumerable`1 source, System.Func`2 selector) [0x00000] in <filename unknown>:0 
	  at Seriti.UI.CarSearchScreen+<HandleSearchCriteriaDownloaded>c__AnonStorey8.<>m__1A () [0x00000] in <filename unknown>:0 
	  at MonoTouch.Foundation.NSActionDispatcher.Apply () [0x00000] in <filename unknown>:0 
	  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00000] in <filename unknown>:0 
	  at Seriti.UI.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-06-07 06:27:01 UTC
This is the problem:

      at System.Linq.Check.SourceAndSelector (System.Object source, System.Object selector)
      at System.Linq.Enumerable.Select[KeyValuePair`2,String] (IEnumerable`1 source, System.Func`2 selector) 
      at Seriti.UI.CarSearchScreen+<HandleSearchCriteriaDownloaded>c__AnonStorey8.<>m__1A ()

I suggest you check the input to see if it's valid - the easiest is probably to catch the exception in the debugger, alternatively you can also dump the data somewhere to see what's actually there.
Comment 2 Dylan 2013-06-07 07:19:54 UTC
How does the exact same code work perfectly in debug and release modes on the simulator yet not on the device?
Comment 3 Rolf Bjarne Kvinge [MSFT] 2013-06-07 08:16:45 UTC
I do not know - there are many reasons why the simulator may behave differently than the real device, but just from the ArgumentNullException it's not obvious what's going on.

I'd start by checking the input data, to see if it's identical between the simulator and the device.
Comment 4 Dylan 2013-06-07 08:20:28 UTC
I have confirmed 100% in Fiddler that the data returned from the respective web service is identical from calls in both the simulator and device. 

So either there is something wrong with the way that the ServiceStack dll is deserializing data on the device, or the runtime is not liking something in the dictionary?
Comment 5 Rolf Bjarne Kvinge [MSFT] 2013-06-07 08:53:34 UTC
From the exception information it looks like criteria.MakesAndModels is null.

It could be that deserialization failed because the managed linker [1] removed code required for deserialization to work. You can easily test this by disabling the linker (in the project's iOS Build options set "Link Behavior" to "Don't link").

[1] http://docs.xamarin.com/guides/ios/advanced_topics/linker
Comment 6 Dylan 2013-06-07 09:27:51 UTC
It seems as though ServiceStack is not deserializing the Dictionary properly. Doesn't appear to be the mono runtime's issue.
Comment 7 PJ 2013-11-19 17:05:56 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 8 Dylan 2013-11-20 05:28:12 UTC
I haven't experienced this issue in a while. This can be closed.
Comment 9 Rolf Bjarne Kvinge [MSFT] 2013-11-20 05:51:22 UTC
Closing then, thanks.