Bug 39824 - SerializationException thrown when serializing an Exception that uses SerializeObjectState
Summary: SerializationException thrown when serializing an Exception that uses Seriali...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 4.2.0 (C6)
Hardware: Other Linux
: --- normal
Target Milestone: Untriaged
Assignee: Andi McClure
URL:
Depends on:
Blocks:
 
Reported: 2016-03-21 22:44 UTC by David Straw
Modified: 2016-04-14 22:13 UTC (History)
4 users (show)

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


Attachments
Simple reproduction case for the issue (1.95 KB, text/plain)
2016-03-21 22:44 UTC, David Straw
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 GitHub or Developer Community 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 David Straw 2016-03-21 22:44:42 UTC
Created attachment 15479 [details]
Simple reproduction case for the issue

In .NET, exception serialization can be implemented either using a deserialization constructor and GetObjectData() or by subscribing to the SerializeObjectState event handler. Doing the latter is apparently not supported in Mono. The problem is that if an Exception class uses this method of serialization, all derived classes must also do so to support serialization. See the "Notes to Implementers" at https://msdn.microsoft.com/en-us/library/system.exception.serializeobjectstate(v=vs.110).aspx

In my particular instance I am deriving from HttpRequestException, which uses the SerializeObjectState event handler to support serialization. I tried doing the same in my derived exception, but it only works in .NET. Under Mono 4.2.2 I get this exception during serialization:

System.Runtime.Serialization.SerializationException: The constructor to deserialize an object of type 'SerializeObjectStateIssueRepro.SerializableException' was not found.
  at System.Runtime.Serialization.ObjectManager.GetConstructor (System.RuntimeType t) <0x7f88d546dfa0 + 0x000aa> in <filename unknown>:0
  at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject (System.Object obj, System.Runtime.Serialization.SerializationInfo info, StreamingContext context) <0x7f88d546dd50 + 0x00120> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject (System.Object obj, System.Runtime.Serialization.SerializationInfo info, StreamingContext context) <0x7f88d546dd50 + 0x001c8> in <filename unknown>:0
  at System.Runtime.Serialization.ObjectManager.FixupSpecialObject (System.Runtime.Serialization.ObjectHolder holder) <0x7f88d546be30 + 0x00122> in <filename unknown>:0
  at System.Runtime.Serialization.ObjectManager.DoFixups () <0x7f88d546e050 + 0x000bf> in <filename unknown>:0
  at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize (System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Runtime.Serialization.Formatters.Binary.__BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) <0x7f88d545a2a0 + 0x000bc> in <filename unknown>:0
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) <0x7f88d54546e0 + 0x00165> in <filename unknown>:0
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage) <0x7f88d54546a0 + 0x0002d> in <filename unknown>:0
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, Boolean fCheck) <0x7f88d54545c0 + 0x00023> in <filename unknown>:0
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) <0x7f88d54545f0 + 0x0001b> in <filename unknown>:0
  at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) <0x7f88d54545a0 + 0x00013> in <filename unknown>:0

I have attached a reproduction case that works in .NET but not in Mono 4.2.2.
Comment 1 Andi McClure 2016-04-14 22:12:52 UTC
Fixed in github master as of PR #2875+#2888 (commit 07c22a0e68b0). With the current schedule the fix will show up in the public release with version 4.6.1.