This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 37171 - DataContractSerializer does not handle ISerializable at all
Summary: DataContractSerializer does not handle ISerializable at all
Status: VERIFIED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Other (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Mac OS
: --- normal
Target Milestone: (C6SR1)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-12-20 15:59 UTC by Aaron Bockover
Modified: 2016-01-28 19:25 UTC (History)
4 users (show)

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


Attachments
Test Case (1.70 KB, text/plain)
2015-12-20 15:59 UTC, Aaron Bockover
Details

Description Aaron Bockover 2015-12-20 15:59:32 UTC
Created attachment 14354 [details]
Test Case

At least since switching to the RS implementation of DataContractSerializer, support for ISerializable has been broken due to not passing the SerializationInfo object as the first parameter to the constructor required by ISerializable at runtime.

The exception:

System.Reflection.TargetParameterCountException: Number of parameter does not match expected count.
  at System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, BindingFlags invokeAttr) <0x103695df0 + 0x0019e> in <filename unknown>:0
  at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x103696ab0 + 0x00064> in <filename unknown>:0
  at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x1036969e0 + 0x00087> in <filename unknown>:0
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) <0x1034cd740 + 0x0002a> in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatReaderInterpreter.ReadISerializable (System.Runtime.Serialization.ClassDataContract classContract) <0x105277350 + 0x00147> in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatReaderInterpreter.ReadFromXml (System.Runtime.Serialization.XmlReaderDelegator xmlReader, System.Runtime.Serialization.XmlObjectSerializerReadContext context, System.Xml.XmlDictionaryString[] memberNames, System.Xml.XmlDictionaryString[] memberNamespaces) <0x105276200 + 0x0017f> in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatReaderGenerator+CriticalHelper+<GenerateClassReader>c__AnonStorey0.<>m__0 (System.Runtime.Serialization.XmlReaderDelegator xr, System.Runtime.Serialization.XmlObjectSerializerReadContext ctx, System.Xml.XmlDictionaryString[] memberNames, System.Xml.XmlDictionaryString[] memberNamespaces) <0x105276130 + 0x000a9> in <filename unknown>:0
  at System.Runtime.Serialization.ClassDataContract.ReadXmlValue (System.Runtime.Serialization.XmlReaderDelegator xmlReader, System.Runtime.Serialization.XmlObjectSerializerReadContext context) <0x1052759f0 + 0x00056> in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlReaderDelegator reader) <0x1052759b0 + 0x0002a> in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize (System.Runtime.Serialization.XmlReaderDelegator reader, System.String name, System.String ns, System.Type declaredType, System.Runtime.Serialization.DataContract& dataContract) <0x105274050 + 0x0057b> in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize (System.Runtime.Serialization.XmlReaderDelegator xmlReader, System.Type declaredType, System.Runtime.Serialization.DataContract dataContract, System.String name, System.String ns) <0x105273fb0 + 0x00068> in <filename unknown>:0
  at System.Runtime.Serialization.DataContractSerializer.InternalReadObject (System.Runtime.Serialization.XmlReaderDelegator xmlReader, Boolean verifyObjectName, System.Runtime.Serialization.DataContractResolver dataContractResolver) <0x10526e7a0 + 0x002c1> in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions (System.Runtime.Serialization.XmlReaderDelegator reader, Boolean verifyObjectName, System.Runtime.Serialization.DataContractResolver dataContractResolver) <0x10526e420 + 0x0020f> in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions (System.Runtime.Serialization.XmlReaderDelegator reader, Boolean verifyObjectName) <0x10526e3e0 + 0x00025> in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) <0x10526e240 + 0x0005d> in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.IO.Stream stream) <0x10526a570 + 0x0005c> in <filename unknown>:0
  at DcsISerializableTest.Main () <0x101feada0 + 0x001e2> in <filename unknown>:0
Comment 1 Aaron Bockover 2015-12-20 16:03:03 UTC
Note: this is a bug in Mono's shim/bridge code to support the RS DCS. Pull Request incoming...
Comment 2 Aaron Bockover 2015-12-20 16:10:57 UTC
Pull request: https://github.com/mono/mono/pull/2372
Comment 3 Alex Rønne Petersen 2015-12-22 09:26:59 UTC
Marking as fixed as PR has been merged.
Comment 4 Arpit Jha 2016-01-06 05:23:05 UTC
************************************************************************************
Reproduce Status: Reproduced
************************************************************************************
I have checked this issue with Mono 4.2.1 (explicit/6dd2d0d) + XS 5.10.1 (build 6) and able to reproduce this issue with the help of bug description.

Steps I have followed:
1.Create a Xamarin Console App.
2.Add  following Reference to Console App.

System.Runtime.Serlization.
Syste.XML

3. Implement the attached test case in Program.cs class.
4. Build and run the application.

Observation : Getting an exception of “System.Reflection.TargetParameterCountException: Number of parameter does not match expected count.”

Screencast: http://www.screencast.com/t/l9jBhvFIgVu
Exception: https://gist.github.com/Arpit360/3d45752ca87af2acc80e

Environment Info: https://gist.github.com/Arpit360/c9aca83e3526c37affe1

***********************************************************************************
Verify Status: Verified

************************************************************************************

I have checked the same with latest mono master : Mono 4.3.2 (master/1b616ca)  + XS : 6.0 (build 2679) and app build and run successfully without any exception.

Screencast: http://www.screencast.com/t/yCepWq2oM
Environment : https://gist.github.com/Arpit360/f202ebd121fdf1db5f29

Hence closing this issue.
Comment 5 Arpit Jha 2016-01-15 05:15:44 UTC
I have checked this issue with latest C6SR1 Mono 4.2.2.28 with the help of attached project and observed that app build and deploy successfully without any exception.

Screencast: http://www.screencast.com/t/plYHZvnYPl
Environment Info:https://gist.github.com/Arpit360/2fd3b86736341972ac56

Note You need to log in before you can comment on or make changes to this bug.