Unity 4.2.2 and DataContractSerializer

Hello

Up until now I have been successfully using the DataContractSerializer from System.Runtime.Serialization namespace.
This was done by having external System.Runtime.Serialization.dll in my project.

Since Unity 4.2.2 this is no longer possible as I receive: following error:
error CS0433: The imported type `System.Runtime.Serialization.DataContractSerializer’ is defined multiple times

I thought that Unity now supports the DataContractSerializer natively, but when I removed if from my project, project compiles correctly but no longer works :frowning: Also in MonoDevelop this namespace is not recognised. Weird.

Is there any way to make it work again?

Thanks for any help.

Tomas

1 Like

I will answer my own question.
Unity now supports the DataContractSerializer, but it is more restrictive, therefore all that is Deserialized has to be annotated by [DataContract] and [DataMember] attributes.

One annoying thing is remaining and that is that MonoDevelop does not recognise the reference and therefore marks all these attributes as errors.

Tomas

Has there been any update to this?
It’s bizarre that 4.2.2 supports [DataContract] when the Editor compiles, but MonoDevelop breaks.

Does anyone know if updating Unity fixes this?

I’ve updated to Unity 5.0 and I’m still experiencing the same problem. Couldn’t find the solution anywhere on the internet. So, just to update, problem still exists and no solution anywhere.
If someone has found a way to bypass this problem and use classes and attributes defined within System.Runtime.Serialization with MonoDevelop/VisualStudio recognizing them, the answer would be much appreciated.

I’m using 5.3.4f1 and I have it working. If you add “c:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity\System.Runtime.Serialization.dll” to assets it will work both in the Unity editor and in your IDE. Also add System.Xml from the same folder. And possible change to “.NET 2.0” instead of the subset. And restart everything, except the computer.