Objects serialized with collections that refer to themselves fails with an exception


In ObjectFactory, there's this check:
        if (property.Type == null)
            // there is no property type and no expected type defined. Give up!
            throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"",
However, if you have a situation where you have an object that has a collection that has an object that has a reference to the first object, property.Type will be null, because it's a reference object.

The solution? Remove that check and serialization works fine. This affects both binary and xml serialization. The following example is a shortened version that shows the situation. I've trimmed it for brevity and removed identifying information. Obviously, this object graph is huge, so this is "fun":

???<Complex name="Root" type="MyNamespace.Model.User, MyNamespace.Model, Version=, Culture=neutral, PublicKeyToken=null" id="1">
    <Complex name="Contact" id="3">
            <Complex name="PreferredLocale" id="12">
                    <Collection name="Contacts1" type="System.Collections.Generic.HashSet`1[[MyNamespace.Model.Contact, MyNamespace.Model, Version=, Culture=neutral, PublicKeyToken=null]], System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                            <Reference id="3" />