Bug 1415 - SOAP Exception failing to deserialize ExceptionDetail
Summary: SOAP Exception failing to deserialize ExceptionDetail
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2011-10-11 07:23 UTC by Justin S.
Modified: 2011-10-18 22:02 UTC (History)
2 users (show)

Tags:
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:
Status:
RESOLVED FIXED

Description Justin S. 2011-10-11 07:23:28 UTC
When an unhandled exception occurs in a remote webservice method MonoTouch raises the following error:

Type: System.Runtime.Serialization.InvalidDataContractException

Message: DataMember property 'System.String Message' on type 'System.ServiceModel.ExceptionDetail' must have both getter and setter.

Stack:
  at System.Runtime.Serialization.SharedContractMap.GetMembers (System.Type type) [0x0007d] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:471 
  at System.Runtime.Serialization.SharedContractMap.Initialize () [0x00040] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/SerializationMap.cs:449 
  at System.Runtime.Serialization.KnownTypeCollection.RegisterContract (System.Type type) [0x0004e] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:919 
  at System.Runtime.Serialization.KnownTypeCollection.DoTryRegister (System.Type type) [0x00046] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:745 
  at System.Runtime.Serialization.KnownTypeCollection.TryRegister (System.Type type) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:723 
  at System.Runtime.Serialization.KnownTypeCollection.InsertItem (Int32 index, System.Type type) [0x00019] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:466 
  at System.Collections.ObjectModel.Collection`1[System.Type].Add (System.Type item) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs:74 
  at System.Runtime.Serialization.DataContractSerializer.RegisterTypeAsKnown (System.Type type) [0x00026] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:238 
  at System.Runtime.Serialization.DataContractSerializer.PopulateTypes (IEnumerable`1 knownTypes) [0x00058] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:226 
  at System.Runtime.Serialization.DataContractSerializer..ctor (System.Type type, IEnumerable`1 knownTypes) [0x00029] in /Developer/MonoTouch/Source/mono/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:74 
  at System.Runtime.Serialization.DataContractSerializer..ctor (System.Type type) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object[] parameters) [0x00110] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:541 
  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00038] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:486 
  at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:466
Comment 1 Justin S. 2011-10-11 19:18:44 UTC
I'm am getting this same error when the service tries to use a FaultContract as well.
Comment 2 Justin S. 2011-10-11 19:35:11 UTC
I have solved the initial problem, the Linker was removing the property on ExceptionDetail. I turned off linking and the unhandled exception correctly flows through.

I am still getting some issues with FaultContracts, but that would be a different problem.

Should the ExceptionDetail class have Preserve(AllMembers=true) ?
Comment 3 Sebastien Pouliot 2011-10-11 20:54:16 UTC
I've been considering (among other things ;-)  to add automatic protection to [DataMember] decorated properties. I think this makes it clear it's something needed (since it affects "Link SDK") . Thanks a lot for spotting (and reporting) this!
Comment 4 Justin S. 2011-10-11 21:09:51 UTC
Ok to fix this without turning off the Linker I included the following within my code:

var x = new System.ServiceModel.ExceptionDetail(new Exception());
if (x.InnerException == null || x.StackTrace == null || x.Type == null || x.HelpLink == null)
	;

I didn't have to reference the Message property within the if statement, but perhaps that should be there as well for completeness.
Comment 5 Justin S. 2011-10-11 21:54:30 UTC
In addition to my last comment, I had to actually perform a dummy operation within that If statement, otherwise it got optimized out :)
Comment 6 Sebastien Pouliot 2011-10-12 08:20:24 UTC
Thanks for the extra details Justin!

Do you have a small test case on which I'll be able to test my fix (beside simply ensuring the type/members are not removed from the assembly) ?
Comment 7 Sebastien Pouliot 2011-10-14 15:16:12 UTC
I'm testing a smarter linker rule wrt serialization (both DataContract and XmlSerialization).

In the mean time you can also add "--linkskip=System.ServiceModel" (in "additional mtouch arguments") as a less intrusive (as in "no code to add" but likely a bigger final .app) option.
Comment 8 Sebastien Pouliot 2011-10-18 22:02:11 UTC
Fixed. Smarter linking coming in the next minor (non-bug fix) version.
5f9271b489ff3e454152bf767de2eaeb6e8f4ada (master)