Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity 4.2.2 and DataContractSerializer

Discussion in 'Scripting' started by tomi-trescak, Oct 30, 2013.

  1. tomi-trescak

    tomi-trescak

    Joined:
    Jul 31, 2013
    Posts:
    78
    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 :( Also in MonoDevelop this namespace is not recognised. Weird.

    Is there any way to make it work again?

    Thanks for any help.

    Tomas
     
    Last edited: Oct 30, 2013
    sejton likes this.
  2. tomi-trescak

    tomi-trescak

    Joined:
    Jul 31, 2013
    Posts:
    78
    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
     
  3. MatthewScott

    MatthewScott

    Joined:
    Aug 25, 2008
    Posts:
    40
    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?
     
  4. sejton

    sejton

    Joined:
    Dec 3, 2012
    Posts:
    7
    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.
     
  5. Zita

    Zita

    Joined:
    Oct 24, 2014
    Posts:
    17
    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.
     
    Last edited: Aug 11, 2016