Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Newtonsoft Json package

Discussion in 'Scripting' started by SLGSimon, Mar 9, 2020.

  1. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    57
    So now that Unity has brought in Newtonsoft.Json.dll in their own package, the docs say:
    "To avoid assembly clashes, please use this package if you intend to use Newtonsoft Json."​

    But the docs for the package say:
    "This is a package intended for internal Unity Development Projects and as such this package is not supported. Use at your own risk."

    So is this package going to be supported now that we're forced to use it?

    (Also it's spelt wrong on https://docs.unity3d.com/Packages/com.unity.nuget.newtonsoft-json@2.0/manual/index.html)

    I should note that I'm using Unity 2019.3.4f1 but it seems the package is for 2020?
     
    ImpossibleRobert and ETGgames like this.
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    5,375
  3. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    57
    It's a new package (com.unity.nuget.newtonsoft-json) which is a dependency of Platforms (com.unity.platforms@0.2) which is a dependency of Entities (com.unity.entities@0.7)
     
    ETGgames likes this.
  4. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    It's a bit uncouth of Unity to force their own version of Newtonsoft Json as a dependency.

    It's pretty easy to keep using your own version though:
    1. Move the "com.unity.platforms" package from Library/PackageCache to your Packages folder
    2. Remove "com.unity.nuget.newtonsoft-json": "1.1.2" from its dependencies in package.json
     
    Last edited: Mar 23, 2020
    labandunga likes this.
  5. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    57
    What do you mean doesn't support IL2CPP? I haven't noticed any problems with it.
     
  6. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    I did encounter this unhelpful error in build after trying Unity's version : currently not available on il2cpp Line: -1


    I've seen this before when trying to use Newtonsoft's Json with AOT compilation.
    I didn't bother investigating too deeply what exactly was missing, and reverted back to https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347
    If you didn't encounter any issues, it might actually be fine for most use cases, I've edited my post above.
     
  7. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    57
    @multivac you were right, versions previous to 2.0-preview don't work with IL2CPP, which is pretty crazy.

    But now the package we have to use is a preview and internal package?
     
  8. Paul_Bronowski

    Paul_Bronowski

    Joined:
    Sep 3, 2014
    Posts:
    55
    @Unity package developers, please resolve this.
     
    PraetorBlue likes this.
  9. christophera_unity

    christophera_unity

    Unity Technologies

    Joined:
    Aug 16, 2018
    Posts:
    17
    Hi all,

    I'm sorry that you all have been experiencing issues with the com.unity.nuget.newtonsoft-json package. I am one of the developers that developed the initial package. Firstly, I'd like to provide some context as to why the package was introduced in the first place. I assume that we are all aware that Unity does not handle strong named assemblies (https://docs.microsoft.com/en-us/dotnet/standard/assembly/strong-named). This means that there can only be one copy of a specific assembly on a system, which is an issue when both packages and users may introduce their own copies of some popular library. Newtonsoft Json is one of these. This lead to the decision to create a package to serve as a common ground for other Unity packages.
    The package is marked as not supported because we don't want users to expect a level of support on par to an official Unity package. The package is supported and we will fix some Unity specific issues, but any issues with Newtonsoft Json itself should be directed back to the developers of the library.
    In no way are we taking away choice from the user. In fact by making this package a common dependency, users can use the local package override to override the newtonsoft json version for everything. Simply copy the package into your packages directory and replace the dll and the AOT dll. The link.xml file can also be modified to your needs. However, keep in mind that any change comes with the risk of breaking things.
    As of version 2, we have IL2CPP support similar to the one here https://github.com/jilleJr/Newtonsoft.Json-for-Unity
    Version 2 will be out of preview soon with support for all Unity platforms. I believe it's using the latest version of newtonsoft json.

    The spelling mistake has been fixed and will be included in the next update!
     
    Last edited: May 6, 2020
    TheSmokingGnu and karl_jones like this.
  10. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    57
    @christophera_unity I have no problem with Unity providing the library (I certainly wouldn't want different copies in my project), but I do have a problem with it being labelled as unsupported and internal. You know people are going to have to put in considerable effort to remove/replace it - not to mention that Unity packages would then be relying on an external json package, surely you aren't going to say that's a supported scenario.

    What I would like to see:
    * Remove the "unsupported" and "internal use" and "use at own risk" texts and replace it with a more friendly reminder that it's a third party library.
    * Since you have made source changes for the AOT version, make the source available online so people can see it and contribute issues/fixes - again you can have some indication here it's a third party dll, but now we are relying on Unity for updates from the original package.
     
  11. christophera_unity

    christophera_unity

    Unity Technologies

    Joined:
    Aug 16, 2018
    Posts:
    17
    @SLGSimon your suggestions and issues have been taken into account. So, a quick update: we have begun some internal discussions to try find the optimal solution to this issue for both Unity and users. This will probably take some time, but I'll update this thread once we find an adequate solution.
    For now, a temporary solution would be to rename the namespace and assembly of newtonsoft json. This would allow you to have your own copy and would avoid any collisions with the package.
     
  12. Yemnefer

    Yemnefer

    Joined:
    Sep 12, 2017
    Posts:
    24
    manually putting
    Code (CSharp):
    1.     "com.unity.nuget.newtonsoft-json": "2.0.0"
    into the manifest.json seems to work, I'm using 2019.2, not sure about the implications tho
     
  13. christophera_unity

    christophera_unity

    Unity Technologies

    Joined:
    Aug 16, 2018
    Posts:
    17
    @Yemnefer The package supports 2018.4 and above as long as NET4 or Net Standard 2.0 is used. There should be no issues using in on 2018.4 and above. We cannot retroactively verify on older versions, so the package is only verified on 2020.1+.
     
    Yemnefer likes this.
  14. Yemnefer

    Yemnefer

    Joined:
    Sep 12, 2017
    Posts:
    24
    good to know, thank you very much.
     
    christophera_unity likes this.
  15. Skotrap7

    Skotrap7

    Joined:
    May 24, 2018
    Posts:
    41
    It looks like the burst preview pacakge 1.3.0-preview.12 has newtonsoft JSON in its .Runtime forlder, which is causing issues when using something that depends on the com.unity.nuget.newtonsoft-json package.

    How would I resolve this correctly?
     
  16. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    57
    The Burst .Runtime folder is outside of Unity, it's a separate environment for the Burst command line tool. What problems are you having?
     
  17. Skotrap7

    Skotrap7

    Joined:
    May 24, 2018
    Posts:
    41
    If you need it, I can set up another project again and give you a screen shot about the error, but basically, Unity reports a compiler error that there are two conflicting versions of NewtonSoft.Json.dll. One is in the com.unity.nuget.newtonsoft-json package, and one is in the burst preview pacakge 1.3.0-preview.12, in the .Runtime folder.

    I didn't need the latest burst preview, so I went through my packages and chose earlier versions that depend on the verified burst 1.2.3 and the problem went away. Also, in burst 1.2.3 the .Runtime folder does NOT contain the Newtonsoft dll. I didn't check every version between 1.2.3 and the latest preview, but this appears to be a new addition. Regardless, as far as package management goes (especially with the strong named assemblies) burst should probably depend on the com.unity.nuget.newtonsoft-json package instead of providing its own.

    If it isn't clear, this is not about Burst actually running, as I'm sure there is no issue in the CLI tool, this is about Unity compilation errors when you have these conflicts in you're packages.

    Let me know if you need that example project, happy to help.
     
unityunity