• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by mhdema n9ne · Nov 13, 2013 at 01:09 AM · serializationmonodevelopunity serializer

Is it possible to use DataContractJsonSerializer?

I have an already established architecture using DataContracts in conjunction with DataContractJsonSerializer but cannot seem to get it working with unity. It suggests a missing assembly reference but I've added the reference and also tried to place the dll in the plugins folder. Has anyone done this or know what the problem might be?

Also I noticed the reference to JsonFX.Json.dll did unity use this for a localization solution? Do you recommend using JsonFX instead?

Comment
nventimiglia

People who like this

1 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mhdema n9ne · Nov 14, 2013 at 08:52 PM 0
Share

Just a note JsonFX was included because of a package that was installed.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by mhdema n9ne · Nov 13, 2013 at 10:12 PM

I still haven't been able resolve my issue with DataContractJsonSerializer but I did find out useful information that I can share.

Firstly unity doesn't actually use the .NET framework which in hindsight is obvious as it would ruin localization--only working on windows. Unity scripts are executed on the .NET 2.0 runtime and as of unity version 3/4 you can use C# 4.0 syntax (default params is an example). Mono which unity runs version 2.6 (not the latest) is comparable to the .NET framework but does not support all the features of 3.5 and 4 versions of dot NET.

Now onto the DataContractJsonSerializer well the DLL I was original looking for System.Runtime.Serialization.dll is .NET 4.0 which I assume isn't supported. Any older version of System.Runtime.Serialization.dll doesn't have a DataContractJsonSerializer because it was actually moved from System.ServiceModel.Web.dll so I tried that in 3.5 with a System.Runtime.Serialization.dll from 3.5 and while everything seemed correct in MonoDevelop unity fired off an error of System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

I was either very close to or on the complete wrong track to resolving this issue. I'm going a different route because in the time it took me to hunt down all this information I could have coded a different solution. Hopefully it will be helpful to someone else and they are more determined to resolve it.

Comment
sivrikaya

People who like this

1 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nventimiglia · Nov 14, 2013 at 10:35 PM 0
Share

Is there a reason you need both sterilizers? Json is a standardized forma. The JsonFX serializer should be compatible with any other serializer. If you already have it installed, why not use it ?

avatar image mhdema n9ne · Nov 14, 2013 at 10:45 PM 0
Share

The JsonFX serializer came with a community package called A* Pathfinding. I wan't to use DataContractJsonSerializer because it works with [DataContract] and their other attributes like [DataMember(EmitDefaultValue = false)]. I have a bunch of classes using that architecture. JsonFX uses similar attributes (like [JsonMember]) so I ended up doing a #ifdef on my envi to switch between the two.

avatar image mhdema n9ne · Nov 14, 2013 at 10:48 PM 0
Share

Sorry I didn't really answer your first question, I don't actually need both serializers I just can't get the one working with unity :-/ More specifically I can't get it compiling in unity.

avatar image mhdema n9ne · Nov 21, 2013 at 06:45 PM 0
Share

JsonFX works with Unity and [DataContract] attributes.

avatar image

Answer by nventimiglia · Nov 13, 2013 at 01:31 AM

Yes you can. You need to find the .net vs 3.5 System.ComponenetModel.DataAnnotations dll and move it into the assets/plugins/ folder.

I personally use both. I use DataAnnotations so that my model objects can easily be validated using model state in my MVC api controller. In unity DataAnnotations doesn't do anything (for me) - I just have it there to save the headache of excluding the attributes in the shared dll. I use JsonFX to do the actual serialization in Unity. I am using JsonFX vs 1.4.1003.3007 using the 2.0.50727 run-time.

Comment
mhdema n9ne

People who like this

1 Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mhdema n9ne · Nov 15, 2013 at 02:00 PM 0
Share

Could you explain this a little further? Were you able to use a functioning DataContractJsonSerializer object working within unity?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

No custom scripts will work.*Using US.* 1 Answer

Serializing strings to XML C# 1 Answer

Unity's Serialization seems to have a maximum depth of 7. How can I serialize a complex data structure with depths > 7? 1 Answer

MonoDevelop auto formating? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges