omer schleifer
omer schleifer

Reputation: 3935

Error serializing inherited property in .NET 4.5

This is a follow up question to:

Serialization breaks in .NET 4.5

I have a property in legacy code which is causing me grief in serialization on .NET 4.5.

This is the property:

 [EditorBrowsable(EditorBrowsableState.Never), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    private new object Value
    {
        get
        {
            return base.Value;
        }
        set
        {
            base.Value = value;
        }
    }

Which was probably introduced to try to hide the "Value" property of the base class. The only solution which worked so far was to the let the serializer know I want to serialize in .NET4. But this is a problem for me. (This configuration should be set only if .NET 4.5 is installed on the traget computer , otherwise an exception is raised).

I guess I can remove the property all together, but since I'm dealing with a large and complicated legacy system I'm not sure what the side effects might be.

So my quesion is twofold:

  1. Why does the inhertied property breaks .NET 4.5 serialization?

  2. What nasty side effects should I expect if I remove the inherited property?

Upvotes: 0

Views: 226

Answers (1)

Praburaj
Praburaj

Reputation: 11537

As Youssef answered on the related post :

In 4.5, the implementation of XmlSerializer was replaced with one that isn't dependent on the C# compiler. While it provides better startup performance and stability, you might be running into a compatibility issue between the implementations.

The configuration setting to use the legacySerializer does not work on 4.0 machines as the corresponding strongly typed Xml config section class does not contain a placeholder for this setting.

Both the issues are going to be addressed in an upcoming update. Until then you can work around the issue by setting the config switch in 4.5 on removing the switch on 4.0.

Upvotes: 1

Related Questions