Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. 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:
    60
    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,597
    HugoStudica likes this.
  3. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    60
    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
    Dr_SuiuS and labandunga like this.
  5. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    60
    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:
    60
    @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
  10. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    60
    @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.
     
    noio and Xarbrough like this.
  12. Yemnefer

    Yemnefer

    Joined:
    Sep 12, 2017
    Posts:
    53
    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
     
    Visartech likes this.
  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+.
     
    codestage and Yemnefer like this.
  14. Yemnefer

    Yemnefer

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

    Skotrap7

    Joined:
    May 24, 2018
    Posts:
    87
    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:
    60
    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:
    87
    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.
     
  18. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    229
    **EDIT** I managed to rebuild the dll's to use the latest newtonsoft Json & it accepts the dll from test-framework.performance

    Is there a way to fix this error? I had to remove the newtonsoft.Json that some addons are using in my project, because in 2020.x it gets stuck in a loop trying to open the editor (editor log has repeated spam about dll being the same name).

    But now those addons don't work with the dll that comes in from com.unity.collections which I need to use. ( com.unity.collections pulls in
    "com.unity.test-framework.performance": "2.3.1-preview", )

    references strong named Newtonsoft.Json in a different folder, versions has to match. Assembly references: 11.0.0.0 Found in project: 12.0.1.0.
     
    Last edited: Oct 15, 2020
  19. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    30
  20. Flindt

    Flindt

    Joined:
    Dec 28, 2016
    Posts:
    78
    is it possible to use this "official" unity packaged version of json - with unity 2019 - and IOS/IL2CPP?

    Thanks
     
  21. pizzaclubgames

    pizzaclubgames

    Joined:
    Oct 22, 2020
    Posts:
    3
    Related to this: We have common dlls that rely on Newtonsoft for Unity. I am happy to move our common code over to new the new com.unity.newtonsoft package but when I try to add https://packages.unity.com/ to Visual Studio as a package source, it didn't work. I know I can manually copy the dll into my projects, but it would be great if unity packages could be imported through Visual Studio so we can stay up to date easily.
     
  22. pizzaclubgames

    pizzaclubgames

    Joined:
    Oct 22, 2020
    Posts:
    3
    I am receiving this error when importing a dll which references the unity newtonsoft library. This seems to be because Unity is looking at the "fileVersion" not the "assemblyVersion" of the dll. fileVersion is 12.0.301.0 and assemblyVersion is 12.0.0.0. Please look into either changing the package to match the fileVersion and assemblyVersion or fix it so that Unity can resolve the same library by checking assemblyVersion instead of fileVersion. Thanks!


    Unable to update following assemblies:Assets/Plugins/lib/Common.dll (Name = Common, Error = 131) (Output: C:\Users\hunni\AppData\Local\Temp\tmp48bb8865.tmp)

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
     
  23. Futtureman

    Futtureman

    Joined:
    Jun 4, 2015
    Posts:
    4
    I am currently using Unity Perception Package which depends on "com.unity.nuget.newtonsoft-json". How can I use this version of json.net in my scripts? I can't give assembly reference to this package.

    Also if import my Json.Net package it causes reference conflict
     
  24. distastee

    distastee

    Joined:
    Mar 25, 2014
    Posts:
    57
    I had the same issue. Upgrading to 2.0.1-preview1 fixed it for me
     
unityunity