Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 3206 [details]
I've hit a few problems trying to load an instance of ObservableCollection<T> serialized from .net with BinaryFormatter.
I've attached my local patch, and I'll walk through the changes:
1) WindowsBase assembly version mismatch
The first problem I hit was that the serialized data specified WindowsBase version 184.108.40.206, but I'm running on profile 4.5, which has version 220.127.116.11. System assemblies are normally mapped to the current framework version, but WindowsBase wasn't in the list, so it was trying to load the 18.104.22.168 assembly for serialization.
My patch adds WindowsBase to the framework_assemblies list in mono/metadata/assembly.c.
2) ObjectReader fails to properly parse objects with missing members
ObjectReader would only read values from the stream if the field could be found on the type, or if the type was primitive. In the case of a non-primitive missing field, the stream would enter an inconsistent state.
My patch to mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs makes ObjectReader always read a value and just throw it away if there is no field.
3) The serialized structure of ObservableCollection<T> doesn't match .net
An BinaryFormatter serialized instance of the .net implementation of ObservableCollection<T> has data for two fields:
The mono implementation of Collection<T> has a field called 'list', but not 'items', so the contents of the collection will not be serialized.
My patch adds an empty 'SimpleMonitor' class, and renames 'list' to 'items' in Collection<T>. This will break compatibility with data serialized in earlier versions of mono, but will improve compatibility with .net. I'm sure a hack could be added to read the old 'list' field, but I'm not sure where would be best.
*I haven't yet tested serialization from mono or its compatibility with .net going the other way. I also haven't dealt with the other fields in ObservableCollection such as _monitor in .net or Collection<T>.syncRoot in mono.
Fixed in master