Bug 11135 - Using Link All with XML serialisation using System.Runtime.Serialization silently fails with flags enum on device only
Summary: Using Link All with XML serialisation using System.Runtime.Serialization sile...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2013-03-13 17:23 UTC by Felix Collins
Modified: 2013-03-13 21:31 UTC (History)
2 users (show)

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


Attachments
Test code in main(). (5.74 MB, application/zip)
2013-03-13 17:23 UTC, Felix Collins
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 Felix Collins 2013-03-13 17:23:43 UTC
Created attachment 3605 [details]
Test code in main().

Attached project.  On device the serialisation of a flags enum fails if the "Link All" flag is set in the project.
Comment 1 Sebastien Pouliot 2013-03-13 20:59:35 UTC
Thanks for supplying a test case, it makes it a lot easier/faster to see what's going on. From memory we should be considering [DataContract] the same as [Preserve] which would allow serializartion to work properly.

The bug title says "silently" but I get an (unhandled) exception right away.

2013-03-13 20:57:07.930 testenum[3381:907] Unhandled managed exception: Enum value '3' is invalid for type 'testenum.Application+SomeTypes' and cannot be serialized. (System.Runtime.Serialization.SerializationException)
  at System.Runtime.Serialization.EnumMap.Serialize (System.Object graph, System.Runtime.Serialization.XmlFormatterSerializer serializer) [0x000fe] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:1014 
  at System.Runtime.Serialization.XmlFormatterSerializer.Serialize (System.Type type, System.Object graph) [0x002af] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlFormatterSerializer.cs:152 
  at System.Runtime.Serialization.SerializationMap.SerializeNonReference (System.Object graph, System.Runtime.Serialization.XmlFormatterSerializer serializer) [0x0008a] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:247 
  at System.Runtime.Serialization.SerializationMap.Serialize (System.Object graph, System.Runtime.Serialization.XmlFormatterSerializer serializer) [0x0006a] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:228 
  at System.Runtime.Serialization.XmlFormatterSerializer.Serialize (System.Type type, System.Object graph) [0x002af] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlFormatterSerializer.cs:152 
  at System.Runtime.Serialization.XmlFormatterSerializer.Serialize (System.Xml.XmlDictionaryWriter writer, System.Object graph, System.Type declaredType, System.Runtime.Serialization.KnownTypeCollection types, Boolean ignoreUnknown, Int32 maxItems, System.String root_ns, Boolean preserveObjectReferences, System.Runtime.Serialization.DataContractResolver resolver, System.Runtime.Serialization.DataContractResolver defaultResolver) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlFormatterSerializer.cs:60 
  at System.Runtime.Serialization.DataContractSerializer.WriteObjectContent (System.Xml.XmlDictionaryWriter writer, System.Object graph) [0x00013] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:414 
  at System.Runtime.Serialization.XmlObjectSerializer.WriteObject (System.Xml.XmlDictionaryWriter writer, System.Object graph) [0x00008] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/XmlObjectSerializer.cs:107 
  at System.Runtime.Serialization.DataContractSerializer.WriteObject (System.Xml.XmlWriter writer, System.Object graph) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:378 
  at testenum.Application.ToXml[TestClass] (testenum.TestClass obj, Boolean pretty) [0x00000] in <filename unknown>:0 
  at testenum.Application.Main (System.String[] args) [0x00007] in /Users/sebastienpouliot/Downloads/Archive-12/testenum/Main.cs:22 


> On device

Note that this is not a device specific. By default the linker is disabled for simulator builds while it's set to "Link SDK" for device builds. IOW with the same options the same exception is thrown on the simulator.
Comment 2 Sebastien Pouliot 2013-03-13 21:09:24 UTC
The [Flags] attribute got removed - and that breaks serialization of some (flags) enums. This will be fixed in the next version.
Comment 3 Felix Collins 2013-03-13 21:11:05 UTC
RE: "Silently". Weird. I saw that exception if I uncommented the the Assert.
But if I commented it out and set a break point I could examine the XML that is
missing the values. Not sure what gives there.

I'm glad the testcase was appreciated.  It took me a while to narrow down the
cause.
Comment 4 Sebastien Pouliot 2013-03-13 21:31:06 UTC
Fixed in master: 556af3d8abcfc483c5e673509c3e7f0e03bc5e65
QA unit test added in same commit.

Felix, it should be in 6.2.2. Can't say why it did not fail silently for me - but there could have been other (unrelated) changes between 6.0.x and 6.2.x