Bug 34137 - Mono binary deserialization fail if field doesn't exist
Summary: Mono binary deserialization fail if field doesn't exist
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 4.0.0
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2015-09-21 17:44 UTC by Andrey Gruzdov
Modified: 2015-09-24 05:33 UTC (History)
3 users (show)

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

repro solution (27.72 KB, application/x-zip-compressed)
2015-09-21 17:45 UTC, Andrey Gruzdov

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:

Description Andrey Gruzdov 2015-09-21 17:44:33 UTC
Steps to reproduce:
1. create class with 2 fields: bool and int[]
2. serialize it using binary formatter to file
3. remove int[] field from class 
4. deserialize file 
=> in .NET 4.5 - everything is ok, missing int[] field is skipped
=> in Mono 4.0.3 - exception:

System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (element=System.Runtime.Serialization.Formatters.Binary.BinaryElement.ObjectReference, reader={System.IO.BinaryReader}, objectId=0, value={XSTest.TestClass}, info=(null)) in C:\buildroot\release\repos\mono\mcs\class\corlib\System.Runtime.Serialization.Formatters.Binary\ObjectReader.cs:250
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (reader={System.IO.BinaryReader}) in C:\buildroot\release\repos\mono\mcs\class\corlib\System.Runtime.Serialization.Formatters.Binary\ObjectReader.cs:150
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (elem=System.Runtime.Serialization.Formatters.Binary.BinaryElement.Assembly, reader={System.IO.BinaryReader}, readHeaders=false, result=(null), headers=(null)) in C:\buildroot\release\repos\mono\mcs\class\corlib\System.Runtime.Serialization.Formatters.Binary\ObjectReader.cs:107
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (serializationStream={System.IO.FileStream}, handler=(null)) in C:\buildroot\release\repos\mono\mcs\class\corlib\System.Runtime.Serialization.Formatters.Binary\BinaryFormatter.cs:177
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (serializationStream={System.IO.FileStream}) in C:\buildroot\release\repos\mono\mcs\class\corlib\System.Runtime.Serialization.Formatters.Binary\BinaryFormatter.cs:134
XSTest.MainClass.Deserialize () in 
XSTest.MainClass.Main (args={string[0]}) in 

XamarinStudio repro solution attached. Run Step1 project to serialize file, Run Step2 to deserialize it and get exception.
Comment 1 Andrey Gruzdov 2015-09-21 17:45:09 UTC
Created attachment 13001 [details]
repro solution
Comment 2 Marek Safar 2015-09-24 05:33:22 UTC
Already fixed in Mono 4.2