I'm using the NetDataContractSerializer. Some of my classes use custom serialization by implementing ISerializable, and others are singletons that use IObjectReference as well.

Inone of the classes being deserialized, a call to SerializationInfo.GetValue returned the IObjectReference itself, instead of the singleton as should have been returned by a call to GetRealObject? Note that the singleton deserialization code works fine everywhere else, it just fails when I deserialize a custom weak-delegate like-class, that uses an open delegate (see http://diditwith.net/2007/03/23/SolvingTheProblemWithEventsWeakEventHandlers.aspx)

If I look in the XML file, it goes wrong at the following line:

<FinalizedTarget
z:Ref="68" i:nil="true"/>

where ref 68 is a singleton object that already got deserialized:

<b:TargetProperty z:Id="68" z:FactoryType="b:PropertySerializationHelper" z:Type="Engine.PropertySerializationHelper" z:Assembly="Engine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">

This smells like a bug to me, as SerializationInfo.GetValue should never return a reference to the IObjectReference itself no?

Note that I actually switched to this custom serialization in an attempt to solve another problem. When using [DataContract] instead of the custom serialization code, I got the error:

A first chance exception of type 'System.InvalidCastException' occurred in Unknown Module. Additional information: Unable to cast object of type 'System.DelegateSerializationHolder' to type 'System.EventHandler`1[Engine.ChangeEventArgs]'.

This seems like the same bug (DelegateSerializationHolder is most likely also an IObjectReference).

Most likely this is a bug in my code, but I'm a bit stuck, so any help is welcome. I failed to load the debug symbols of System.Runtime.Serialization for some reason, so could not debug Microsoft's code.

If more information is needed, the project is available at code.google.com, I just need to clean it up a bit.