Search Unity

Feedback [DOTS] Why are you constantly adding and removing Newtonsoft.JSON from the dependencies

Discussion in 'Entity Component System' started by iamarugin, May 1, 2020.

  1. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Last three version updates my project exploded with errors and requires reimport after that, because Newtonsoft.Json was added or removed from the dependencies of the dots stack. I am using Newtonsoft.Json in my project too and I needed to remove it or add back to the project. This was an intended changes or something wrong is going on on my end? And why this is happening?
     
  2. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Also after update to Entities 10.0 project is not compiled, with following errors:
    Code (CSharp):
    1.  
    2. Assets\Scripts\Services\models\SaveManager.cs(60,15): error CS0012: The type 'JsonReader' is defined in an assembly that is not referenced. You must add a reference to assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
    3.  
    4. Assets\Scripts\Services\models\SaveManager.cs(60,15): error CS1674: 'BsonDataReader': type used in a using statement must be implicitly convertible to 'System.IDisposable'
    5.  
    But the problem is, that I referenced Newtonsoft.Json in my assembly:

    Looks like the last error is because of com.unity.nuget.newtonsoft-json@2.0.0-preview and AOT changes in it.
     
    Last edited: May 1, 2020
  3. Radu392

    Radu392

    Joined:
    Jan 6, 2016
    Posts:
    210
    Valid question. I had newton json in my project too and when I updated my project, the package manager decided to download its own, breaking my whole project. Since it was the first time dealing with this, it took me several hours to figure out how fix the problem. Can’t the package manager figure out that that dependency is already in the project and link to it instead of downloading a new one? Or at least warn us that updating a package will doom the project into oblivion?
     
  4. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    962
    Can you enable Auto Reference on the dll?
     
  5. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    No, I can't, because then my assemblies don't see Newtonsoft.JSON at all.
     
  6. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,087
    I just copied unity's netwonsoft folder from
    \Library\PackageCache
    to
    \Packages
    and replaced with other netwonsoft (leaving their package.json). Not sure if that will fix your issues.
     
  7. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
  8. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Looks like Unity's version of Newtonsoft.JSON is not compatible with Newtonsoft.JSON.Bson, that I am using in the project.
     
  9. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Good think we've moved away from using Newtonsoft.JSON to GameDevWare JSON. It's a great package with a solid suite of extension/customization options. Used it for exporting JSON and for consuming a couple of API's.
    At some point when upgrading to newer Entities package we had the same problem, but luckily Newtonsoft package was used only in a couple of places, so we just switched away from it.
     
  10. coldwarrior5

    coldwarrior5

    Joined:
    Nov 9, 2016
    Posts:
    12
    The same thing happened to me, whenever they change the dependency it breaks my whole code.
     
    Nyanpas likes this.
  11. coldwarrior5

    coldwarrior5

    Joined:
    Nov 9, 2016
    Posts:
    12
    Does anybody know how to remedy the issue? I tried following some of the comments above but was unsuccessful.
     
  12. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
  13. coldwarrior5

    coldwarrior5

    Joined:
    Nov 9, 2016
    Posts:
    12
    Thank you so much for the help, that was exactly the solution!

    For anyone else that comes across this issue, the solution is to add this line
    Code (CSharp):
    1. "com.unity.nuget.newtonsoft-json": "2.0.0"
    to the manifest.json file since Unity doesn't do it automatically. The manifest.json file is located under the Project folder\Packages. Then you can safely delete the Newtonsoft.Json.dll from your Assets folder and use the Unity's implementation. The Newtonsoft.Bson.Json.dll no longer complains about lack of Newtonsoft.Json.dll.