Bug 13506 - Serializing and deserializing a Dictionary in latest beta
Summary: Serializing and deserializing a Dictionary in latest beta
Status: RESOLVED DUPLICATE of bug 13341
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.3.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2013-07-26 09:12 UTC by Mike James
Modified: 2013-08-29 19:13 UTC (History)
3 users (show)

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


Attachments
Example code that crashes on the device (2.26 KB, text/plain)
2013-07-26 10:14 UTC, Steve Meagher
Details
Device console crash report (106.76 KB, text/plain)
2013-07-26 10:16 UTC, Steve Meagher
Details
DictionaryTest complete project (3.19 MB, application/zip)
2013-08-29 17:19 UTC, Steve Meagher
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 DUPLICATE of bug 13341

Description Mike James 2013-07-26 09:12:18 UTC
A customer has reported issues serializing and deserializing a
Dictionary. He is consistently able to crash his iPad doing this. 

The Dictionary is <int, enum>. If he adds DataContract/DataMember
attributes to the enum, it no longer crashes the device but the object
deserializes to null (on both device and simulator). If I use a class
instead of an enum it works.
Comment 2 Steve Meagher 2013-07-26 10:14:02 UTC
Created attachment 4451 [details]
Example code that crashes on the device

This code works as expected on the simulator but crashes on the device when attempting to deserialize the Dictionary.

This code has previously worked (prior to Xamarin.Studio).  I hadn't tried running the app for a few months.
Comment 3 Steve Meagher 2013-07-26 10:16:31 UTC
Created attachment 4452 [details]
Device console crash report
Comment 4 Rolf Bjarne Kvinge [MSFT] 2013-07-29 18:44:30 UTC
This works if I disable generics value sharing.

Zoltan, can you have a look?
Comment 5 Zoltan Varga 2013-07-29 20:27:53 UTC
This is the same as #13341.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2013-07-30 06:49:06 UTC

*** This bug has been marked as a duplicate of bug 13341 ***
Comment 7 Steve Meagher 2013-08-29 17:19:03 UTC
Created attachment 4755 [details]
DictionaryTest complete project
Comment 8 Zoltan Varga 2013-08-29 17:39:28 UTC
I can reproduce this with 6.4.3, it now fails with a different error:

2013-08-29 23:25:30.708 DictionaryTest[553:907] Unhandled managed exception: Cannot cast from source type to destination type. (System.InvalidCastException)
  at (wrapper managed-to-native) object:__icall_wrapper_mono_object_castclass_unbox (object,intptr)
  at System.Collections.Generic.Dictionary`2[System.Int32,DictionaryTest.TestEnum].ToTValue (System.Object value) [0x00053] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:708 
  at (wrapper unknown) object:gsharedvt_in ()
  at (wrapper unknown) object:gsharedvt_out ()
  at System.Collections.Generic.Dictionary`2[System.Int32,DictionaryTest.TestEnum].System.Collections.IDictionary.Add (System.Object key, System.Object value) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:722 

So its a dup of:
https://bugzilla.xamarin.com/show_bug.cgi?id=14026

That bug has been fixed, and the fix is in the 6.4.4 release which afaik is available in the alpha channel. Sorry for the confusion.
Comment 9 Steve Meagher 2013-08-29 18:48:44 UTC
I tried the Alpha channel and got the same result. Here is the error message:

System.InvalidCastException: Unable to cast object of type 'DictionaryTest.TestEnum' to type 'DictionaryTest.TestEnum'.
  at at (wrapper managed-to-native) object:__icall_wrapper_mono_object_castclass_unbox (object,intptr)
  at System.Collections.Generic.Dictionary`2[System.Int32,DictionaryTest.TestEnum].ToTValue (System.Object value) [0x00053] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:708
  at at (wrapper unknown) object:gsharedvt_in ()
  at at (wrapper unknown) object:gsharedvt_out ()
  at System.Collections.Generic.Dictionary`2[System.Int32,DictionaryTest.TestEnum].System.Collections.IDictionary.Add (System.Object key, System.Object value) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:722
  at System.Runtime.Serialization.DictionaryTypeMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id) [0x000a4] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:881
  at System.Runtime.Serialization.SerializationMap.DeserializeObject (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer) [0x0003a] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:264
  at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializeByMap (System.Xml.XmlQualifiedName name, System.Type type, System.Xml.XmlReader reader) [0x000d3] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlFormatterDeserializer.cs:252
  at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00302] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlFormatterDeserializer.cs:194
  at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Xml.XmlReader reader, System.Type declaredType, System.Runtime.Serialization.KnownTypeCollection knownTypes, IDataContractSurrogate surrogate, System.Runtime.Serialization.DataContractResolver resolver, System.Runtime.Serialization.DataContractResolver defaultResolver, System.String name, System.String ns, Boolean verifyObjectName) [0x0007e] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlFormatterDeserializer.cs:65
  at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlDictionaryReader reader, Boolean verifyObjectName) [0x00024] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:360
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlObjectSerializer.cs:76
  at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlReader reader) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:345
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.IO.Stream stream) [0x0000d] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlObjectSerializer.cs:66
  at DictionaryTest.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00086] in /Users/sam/DictionaryTest/DictionaryTest/AppDelegate.cs:57
  at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at DictionaryTest.Application.Main (System.String[] args) [0x00008] in /Users/sam/DictionaryTest/DictionaryTest/Main.cs:16
Comment 10 Steve Meagher 2013-08-29 18:50:15 UTC
Here is my current set-up:

=== Xamarin Studio ===

Version 4.1.9 (build 6)
Installation UUID: 36f870a5-a2fe-447e-a8a6-ebf61bb1270e
Runtime:
	Mono 3.2.2 ((no/a0fc6ba)
	GTK+ 2.24.20 theme: Raleigh
	GTK# (2.12.0.0)
	Package version: 302020000

=== Apple Developer Tools ===

Xcode 4.6.2 (2067.2)
Build 4H1003

=== Xamarin.iOS ===

Version: 6.4.4.12 (Business Edition)
Hash: 62e07d5
Branch: 
Build date: 2013-26-08 14:21:47-0400

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.Android ===

Version: 4.8.2 (Starter Edition)
Android SDK: /Users/sam/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
Java SDK: /usr
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-11M4406)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)

=== Build Information ===

Release ID: 401090006
Git revision: 123fc693ab9ba2690f93fcfe2cd3499335049ff4
Build date: 2013-08-06 15:11:38+0000
Xamarin addins: ad4a498b75333e43547e87574c1ec8c7cae05de0

=== Operating System ===

Mac OS X 10.7.5
Darwin SM-MBP.local 11.4.2 Darwin Kernel Version 11.4.2
    Thu Aug 23 16:25:48 PDT 2012
    root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
Comment 11 Zoltan Varga 2013-08-29 19:06:56 UTC
I have the same version, and can no longer reproduce this. Did you do a full rebuild ?
Comment 12 Steve Meagher 2013-08-29 19:13:36 UTC
No!  But I did just then and it worked.  Awesome, thanks!