Bug 15027 - Exception when trying to serialize object containing Dictionary<string, string> property.
Summary: Exception when trying to serialize object containing Dictionary<string, strin...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.0.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2013-09-26 18:55 UTC by gtas
Modified: 2013-09-30 08:03 UTC (History)
2 users (show)

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


Attachments
Sample project showing the problems (14.50 KB, application/zip)
2013-09-27 09:42 UTC, gtas
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 gtas 2013-09-26 18:55:42 UTC
2013-09-17 17:19:59.536 BugSenseXamariniOSClient[585:907] System.Runtime.Serialization.SerializationException: There was an error during serialization for object of type BugSense.Core.Model.BugSenseExceptionRequest ---> System.NullReferenceException: Object reference not set to an instance of an object
  at System.Runtime.Serialization.Json.JsonSerializationWriter.WriteObjectContent (System.Object graph, Boolean top, Boolean outputTypeName) [0x002fb] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationWriter.cs:127 
  at System.Runtime.Serialization.Json.TypeMap.Serialize (System.Runtime.Serialization.Json.JsonSerializationWriter outputter, System.Object graph, System.String type) [0x00072] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs:198 
  at System.Runtime.Serialization.Json.JsonSerializationWriter.WriteObjectContent (System.Object graph, Boolean top, Boolean outputTypeName) [0x00507] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationWriter.cs:154 
  at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObjectContent (System.Xml.XmlWriter writer, System.Object graph) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:247 
  at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject (System.Xml.XmlWriter writer, System.Object graph) [0x00008] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:212 
  --- End of inner exception stack trace ---
  at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject (System.Xml.XmlWriter writer, System.Object graph) [0x00023] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:219 
  at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject (System.Xml.XmlDictionaryWriter writer, System.Object graph) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:225 
  at System.Runtime.Serialization.Json.DataContractJsonSerializer.WriteObject (System.IO.Stream stream, System.Object graph) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:205 
  at BugSense.Core.Helpers.Extensions.SerializeToJson[BugSenseExceptionRequest] (BugSense.Core.Model.BugSenseExceptionRequest obj) [0x00000] in <filename unknown>:0 : Serialization FAILED: {0}
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-09-27 06:36:37 UTC
Can you please attach a self-contained test case? That will ensure we're testing the same as you.
Comment 2 gtas 2013-09-27 09:42:20 UTC
Created attachment 5007 [details]
Sample project showing the problems

If you press the With LogData button, you will experience an exception in the output window, the exception is thrown only when testing in a device.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2013-09-27 10:00:31 UTC
This works if I disable the linker, so it seems linker-related.
Comment 4 gtas 2013-09-27 10:06:05 UTC
Does that mean I have to do something to work? is there a solution? Or you just mention it to forward to a colleague of yours?
Comment 5 Rolf Bjarne Kvinge [MSFT] 2013-09-27 10:21:23 UTC
Both :)

You can workaround in the project's iOS Build options by changing "Linker behavior" to "Don't link" (this has a few downsides though: most importantly the app will be significantly bigger, and build times slower).
Comment 6 Sebastien Pouliot 2013-09-27 10:22:28 UTC
> Or you just mention it to forward to a colleague of yours?

Both for you (workaround) and me.

> is there a solution? 

There's two workarounds (until it's fixed).

1. like mentioned above you could disable the managed linker (but it's a bit drastic).

2. It does work (for me) if you only disabled linking System.dll, i.e. add the following "Additional mtouch arguments" to your Project Options, iOS Build

    -linkskip=System
Comment 7 Sebastien Pouliot 2013-09-27 10:37:35 UTC
3. an even smaller workaround is to add the following (somewhere) inside your application

			Dictionary<string,string> d = new Dictionary<string, string> ();
			if (d.Keys == null) {
				// that's because it's used by reflection (in JasonSerializationWriter) 
				// but it might not be used anywhere else in the linked application
			}

That will hint the linker to keep the "Keys" properties and ensure it can be used thru reflection when doing the Json serialization.
Comment 8 Sebastien Pouliot 2013-09-28 13:21:32 UTC
Fixed in master 3665c203817139fab860c174e85da5e761a99e3e
Comment 9 gtas 2013-09-29 11:35:21 UTC
Well done, we should expect to work in the next stable release?
Comment 10 gtas 2013-09-29 14:03:28 UTC
Last workaround seems to working fine for now. Thanks.
Comment 11 Sebastien Pouliot 2013-09-30 08:03:42 UTC
It could be in 7.0.2, but more likely in 7.0.3, depending on when they get released. The bug number will be part of the release notes (to confirm).