Search Unity

Conflict between Asset's Newtonsoft and PackageManager's Newtonsoft

Discussion in 'Package Manager' started by PotatoVeg, Mar 10, 2020.

  1. PotatoVeg

    PotatoVeg

    Joined:
    Jan 28, 2017
    Posts:
    12
    Hey guys,

    (Unity 2019.3.4f1)
    So i want to start my new project and i wanted to use Entities in it.

    I have already installed it using the packagemanager and all the requirements needed and everything is fine, i have created myself a popup system that i exported to a package and i imported it to the new project, the package contains the Newtonsoft.Json.dll plugin and i get an error that says:
    "PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included for the current platform. Only one assembly with the same name is allowed per platform".

    From what i see, Entities are using "Platforms" which contains Newtonsoft Json, therefore the issue lays there where now i have 2 assemblies with the same name as mentioned in the issues above which also causes scripts not to compile such as TextMeshPro and UnityEngine.UI.

    If i am removing the Newtonsoft Json dlls from my assets folder then my popup system scripts that use it will not compile (), if i am removing the Newtonsoft Json from the Library/PackageCache of the project it will compile but the next time i open the project unity will re-add that and repeat the issue.

    If i remove Entities completely everything works fine with no issue but i want to use Entities in this project.

    One of the "solutions" i came across is renaming the dlls in the Assets folder to have a different name than the ones that came from the PackageManager but i don't think its something that should be done.

    What do i need to do to solve this issue?
    Would appreciate any help with this problem.
     
    Last edited: Mar 10, 2020
    AdamBebko and kastus like this.
  2. Onat-H

    Onat-H

    Joined:
    Mar 11, 2015
    Posts:
    195
    I have the same problem with a third party asset. Does anyone have an idea what to do?
     
  3. supita_unity

    supita_unity

    Unity Technologies

    Joined:
    Dec 13, 2019
    Posts:
    226
    Hey,

    Have you tried updating Entities package to its latest available version?

    Cheers,

    Supi
     
  4. PotatoVeg

    PotatoVeg

    Joined:
    Jan 28, 2017
    Posts:
    12
    yes i did, i even had to downgrade Visual Studio Code Editor to 1.1.3 from 1.1.4 because it was causing UnityEngine.UI to not compile and become missing.

    but that's not the issue, the Entities package is not where the problem is, Entities are using the package called "Platforms" and one of the dependencies of that package is "Nuget Newtonsoft-Json" which where the issue begins, by having that package AND your own Newtonsoft-Json DLL sitting in assets causing the conflict.

    there are a few approaches but not all gives a solution:
    1) by renaming the DLL sitting in assets does stop the conflict and makes everything work out (SOLUTION)
    2) by removing the DLL sitting in assets causing everything that uses it (user made scripts) not to compile (NOT A SOLUTION)
    3) by deleting the folder of the newtonsoft from your project's Library/PackageCache will stop the conflict but will return once unity is closed and reopens (TEMPORARY SOLUTION)
     
    sikoby likes this.
  5. dsavickij

    dsavickij

    Joined:
    May 17, 2019
    Posts:
    12
    PutridEx and Argument like this.
  6. wx3labs

    wx3labs

    Joined:
    Apr 5, 2014
    Posts:
    77
    I'm encountering the same issue. I created a package that I use in multiple projects that depends on Newtonsoft Json. As far as I can tell, there's no way to use it in a package that also uses Entities. And yes, I'm on the latest version of Entites.
     
  7. PotatoVeg

    PotatoVeg

    Joined:
    Jan 28, 2017
    Posts:
    12
    Like i said earlier:
    One of the "solutions" i came across is renaming the dlls in the Assets folder to have a different name than the ones that came from the PackageManager but i don't think its something that should be done.

    that will let you work with entites but like i said i dont think its something that should be done because perhaps its an issue from unity for not spotting an issue like this can raise.
     
  8. wx3labs

    wx3labs

    Joined:
    Apr 5, 2014
    Posts:
    77
    I wasn't able to get that solution to work. Specifically, I renamed Newtonsoft.Json.dll -> Newtonsoft.Json2.dll in the Assemblies/Windows directory. I got the same "multiple precompiled assemblies" error after importing the Entities package. Is there something else you did to get that to work?
     
  9. PotatoVeg

    PotatoVeg

    Joined:
    Jan 28, 2017
    Posts:
    12
    i renamed all under Assemblies, not only the windows directory one.
    notice it says "PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included for the current platform. Only one assembly with the same name is allowed per platform",
    that means ANY dll with that name will cause this conflict therefore i suggest to rename all the Newtonsoft.Json.dll
    under Assemblies folder in the plugin.
     
  10. wx3labs

    wx3labs

    Joined:
    Apr 5, 2014
    Posts:
    77
    I'll give that a try, thanks!
     
  11. dsavickij

    dsavickij

    Joined:
    May 17, 2019
    Posts:
    12
    And what to do, when you're using plugin that came from 3rd party and its dependant on Newtonsoft.Json, and you can't change assembly name since then plugin throws errors that he can't find dll and your plugin might crash during runtime?
     
    Mazyod likes this.
  12. PotatoVeg

    PotatoVeg

    Joined:
    Jan 28, 2017
    Posts:
    12
    I am yet to encounter such issue since i am not really using 3rd party plugins at least atm, especially not ones that use Newtonsoft.Json, so far everything in my project is my own development (regardless of the system if its popups, assetbundles, localization and so on), therefore i have no answer to that yet. sorry :(
     
  13. CX-MD

    CX-MD

    Joined:
    Oct 30, 2019
    Posts:
    5
    I was having a similar issue and it was driving me crazy. It all started after trying to test out ECS. I had another Newtonsoft JSON package installed from https://github.com/jilleJr/Newtonsoft.Json-for-Unity and started to get the "Multiple precompiled assemblies with the same name Newtonsoft.Json.dll" error when compiling. If you look in "Library > PackageCache" you will most likely see a folder called "com.unity.nuget.newtonsoft-json@1.1.2" or something similar. Inside that folder is a README.md which I looked at. It had instructions for using the package. I replaced my jilleJr package in the manifest.json with "com.unity.nuget.newtonsoft-json": "2.0.0-preview" and everything is compiling again. It appears that Unity is now including Newtonsoft JSON in certain cases. This fixed my issue. Maybe it will help you too...
     
  14. AdamBebko

    AdamBebko

    Joined:
    Apr 8, 2016
    Posts:
    168
    I'm having the same problem
     
  15. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Our team is well aware that this is still a problem. The good news is that the team know of a great way to address this but right now, this is no ETA that they can provide at present.
     
  16. Alpha7Wolf

    Alpha7Wolf

    Joined:
    Oct 20, 2016
    Posts:
    6
    Great News Thank you!
    But when do get the great way?
     
  17. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    I'm not really privy to precisely what the method would be but it's more of a multi-team effort thing that is needed for the proposed idea. It's incredibly early stages but something the team thinks they can tackle. We'll be sure to share more news when we have updates.
     
    AdamBebko likes this.
  18. marck_ozz

    marck_ozz

    Joined:
    Nov 30, 2018
    Posts:
    107
    I was about to write that this issue was a "Showstopper" for my project until I read this comment. Thank you!!

    Also with the workaround by @christophera_unity in here: https://forum.unity.com/threads/newtonsoft-json-package.843220/#post-5619919

    This fixed almos all my errors. Some other was solved by modifying the manifest but the root problem is was the same, having 2 Newtonsoft dll in the project and then try to repleace one of them.

    I was using this solution in my project https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347

    I just never can't be mad with Unity but please fix this or give us another "more friendly" workaround or just the chance to select the .json NET solution of our choise.

    @UnityMaru, @christophera_unity.
     
    Ziplock9000 and supita_unity like this.
  19. joanpescador

    joanpescador

    Joined:
    Dec 21, 2016
    Posts:
    122
    Any update about this issue? 3 months since last comment. Do you have yet any ETA? Is shocking how this setback let you totally stuck.
     
  20. PetraCephas

    PetraCephas

    Joined:
    Mar 27, 2014
    Posts:
    16
    Any update on this know breaking issue?
     
  21. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    I've checked with the team and there isn't any progress at present. The workaround remains the same:

    - Make your project depend on "com.unity.nuget.newtonsoft-json" instead of having a Newtonsoft.Json asset in your project

    - If the above is not possible, e.g. because you have custom changes in the code, embed the "com.unity.nuget.newtonsoft-json" package in the project and adapt it to your needs (see https://docs.unity3d.com/Manual/upm-embed.html and https://docs.unity3d.com/ScriptReference/PackageManager.Client.Embed.html)
     
  22. bhupiister

    bhupiister

    Joined:
    Dec 13, 2019
    Posts:
    42
    @UnityMaru Today i tried upgrading my project from 2018.4.22 to 2019.4.21f1. And i was also prompted for asset database version change to latest and i accepted that. Now i get multiple errors, to name few.

    PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Google.VersionHandler.dll included or the current platform. Only one assembly with the same name is allowed per platform. Assembly paths:
    Assets/ExternalDependencyManager/Editor/Google.VersionHandler.dll
    /home/bhupi/Unity projects/Sample/Sample1/Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager/Editor/Google.VersionHandler.dll

    PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Google.VersionHandler.dll included or the current platform. Only one assembly with the same name is allowed per platform. Assembly paths:
    Assets/ExternalDependencyManager/Editor/Google.VersionHandler.dll
    /home/bhupi/Unity projects/Sample/Sample1/Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager/Editor/Google.VersionHandler.dll

    AssetImporter is referencing an asset from the previous import. This should not happen.
     
  23. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Hm, I've chat to the team about this and a bug report would be handy to look into this. Are you able to submit one for me and let me know of the ID?
     
  24. bhupiister

    bhupiister

    Joined:
    Dec 13, 2019
    Posts:
    42
    I finally moved to 2019.4.21f1 successfully and hence cannot reproduce it. But it seemed that it was creating another plugin folder with small "p" where i already had one with big "P" and i think it was happening because it could not find one of the mentioned plugin folder, unity assumed that the dependent libraries are not available and hence use to make a duplicate copy from "/Library/PackageCache/". So finally i deleted existing plugin folder and let it re-import completely from the PackageCache, and finally the migration was successful.

    Would this info be sufficient for you ?
     
  25. TahneeSmith

    TahneeSmith

    Joined:
    Oct 27, 2016
    Posts:
    5
    Can anyone explain why renaming a DLL works to solve the conflicts issue?

    (maybe @UnityMaru can explain?)
     
  26. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    An actual bug report seems like the only thing that would help at this point. If you can no longer repro, then this doesn't seem a sufficient lead for an investigation to be done.

    Your mention of a plugin folder with lowercase and uppercase P does not seem relevant with the error messages you previously posted, which pointed to the problem being that Google's "ExternalDependencyManager" was present twice in the project, once under Assets (probably imported from a .unitypackage/Asset Store package) and once under Packages (added through UPM).

    I'm not sure that changing the casing of a DLL name solves a DLL conflict, but I know the ScriptingPipeline uses assembly (DLL) names to create some internal "map" and will bork on duplicate DLL names. This is actually what was happening here. But even with different names, if two versions of a DLL are included in a project, it could (and would typically) result in compilation errors because two different DLLs define the same symbols (namespaces and class names) and the compiler doesn't know which one to use.

    So it wasn't just a renaming thing. In fact, I think the first user's problem got solved without the user realizing, and their comment about the P/p change confused things into think that this was the solution.
     
    DangerIncreased likes this.
  27. cgrow67

    cgrow67

    Joined:
    May 31, 2016
    Posts:
    52
    I upgraded to 2021.1.9f1 today and this is now an issue for me. Its time to make a stand on Json.Net. Stand on one side of the road or the other. Microsoft had the exact same problem and built System.Text.Json with help from NewtonSoft. Go left or right and let your developers know what your doing so we all can use Json without this headache.
     
  28. cgrow67

    cgrow67

    Joined:
    May 31, 2016
    Posts:
    52
    Holly smokes..after looking at GIT diffs it seems there is a change to package-lock.json which describes dependencies.

    Code (CSharp):
    1.  
    2.       "com.unity.collab-proxy": {
    3.       "version": "1.5.7",
    4.       "depth": 0,
    5.       "source": "registry",
    6.       "dependencies": {
    7.         "com.unity.nuget.newtonsoft-json": "2.0.0"
    8.       },
    9.       "url": "https://packages.unity.com"
    10.     },
    We bring in another JSON.Net package. and this is where the problems lie.
    When I look up the details on this package you find it is not supported.. (Ouch)
    https://docs.unity3d.com/Packages/com.unity.nuget.newtonsoft-json@2.0/manual/index.html

    So, I can't add this independently and the documentation says I shouldn't use it.
    This is a package intended for internal Unity Development Projects and as such this package is not supported. Use at your own risk.

    Unity- Its time to put on the big boy pants and get your dependencies in order!
    If your coders need newtonsoft just make it an official package and support the darn thing.
    So many of us use this, it would really make sense to include it.
    Either use something different internally that doesn't conflict or make it available so we can all use it!

    I need to get my code working and the only solution is removing parentElement's implementation of newtonsoft.
    How long will it be until this dependency is removed and my code again fails due to lack of newtonsoft?

    I am also not sure how platform compatible com.unity.nuget.newtonsoft-json is?
    parentElements package goes to all platforms.
     
    Last edited: May 29, 2021
    PandaArcade and bdovaz like this.
  29. DrzwiPercepcji

    DrzwiPercepcji

    Joined:
    Jan 10, 2018
    Posts:
    3
    lipengkai, AdamBebko and cgrow67 like this.
  30. They probably don't support it, because they are planning to remove it as a dependency, eventually. Imagine if they start to support it and then they rip it out. This way at least you know that you shouldn't use it.
    Or you can start using it, when you update Unity packages you will be notified about the missing lib and you can add it. And you probably will want to switch to System.Text.Json too, when it becomes available.

    It's smaller deal than it seems. It's not like breaks at users', it breaks when you change your project.

    Edit:
    BTW, apparently Unity is indecisive about this one. In 2021.2a17:
     
    Last edited by a moderator: Jun 1, 2021
    cgrow67 likes this.
  31. jaclemoe

    jaclemoe

    Joined:
    May 10, 2020
    Posts:
    2
    Solution that worked for me:
    • Copy Library/PackageCache/com.unity.nuget.newtonsoft-json to Packages/
    • Remove com.unity.nuget.newtonsoft-json from packages-lock.json
    • Delete or copy replacement Newtonsoft.Json.dll files into Packages/com.unity.nuget.newtonsoft-json
    This basically hard sets com.unity.nuget.newtonsoft-json in your project Packages/ dir, so Unity doesn't pull down it's own version of the dlls. This then allows you to override them by pasting the exact version in you want.
     
    CodeRonnie, kbm and cgrow67 like this.
  32. cgrow67

    cgrow67

    Joined:
    May 31, 2016
    Posts:
    52
    This is the best solution if your not using collab... very simple.

    Newtonsoft.Json is a really popular package so inserting it by default into our projects feels like a dirty trick..
    In Visual Studio when you look at reference properties there is an Alias property you can use to fix stuff like this.
    Possibly packages should have something like this where you could modify the namespace when its brought into a project?

    Another option would be to have a Newtonsoft.Json package that we can all share.
    I could use it, apparently your team needs it and I'm sure there are others that would move to using it.

    Please..
     
    jkoutavas and madfu like this.
  33. BobbyVR

    BobbyVR

    Joined:
    Aug 12, 2017
    Posts:
    6
    Delete your Project\Library\PackageCache contents. Then re build the project without this dll/pachage confilcts.
     
  34. RemyJacks

    RemyJacks

    Microsoft Employee

    Joined:
    Jan 4, 2019
    Posts:
    4
    I hit this issue and resolved it by removing version control from my project.
     
  35. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    This is really annoying. All the solutions posted here aren't working for me. I needed the jobs package and off goes my sanity. Lovely.
     
  36. Tomcat9

    Tomcat9

    Joined:
    Dec 10, 2020
    Posts:
    6
    First time? Personally, at this point I've probably spent more time debugging buggy Unity than my actual project. With each new update, Unity seems to release more bugs than bugs life, and more glitches in its core systems than Metal arms: glitch in the system. Terrible.
     
    kennel_ likes this.
  37. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    In your case, a bug report is probably going to be worthwhile if you've tried all the workarounds.

    https://unity3d.com/unity/qa/bug-reporting

    Let me know the ID of it so i can flag with the team directly.
     
  38. grentle

    grentle

    Joined:
    May 14, 2016
    Posts:
    7
    Perfection, thanks for posting
     
  39. Devilers

    Devilers

    Joined:
    Jan 9, 2016
    Posts:
    1
    Holy crap... This issue is still isn't fixed and internal version of Newtonsoft.Json breaks completely plugins that were compiled with specific version that don't fit with supplied by Unity.
    The only solution is to completely remove collab package... Why it isn't fixed yet? That's almost ONE year old already...

    P.S. Unity version 2021.1.15f1, using Nethereum library which was builded using specific version of Newtonsoft.Json.
     
    firstuser likes this.
  40. shraa1

    shraa1

    Joined:
    Sep 2, 2013
    Posts:
    6
    Wow, not only is this an issue with custom packages, many of the unity packages themselves, when imported together in the same project, are giving this issue. I'm surprised that this bug is still a thing.

    Solutions posted here are not really helpful, like deleting version control, etc. What happens when we delete the affecting files from PackageCache, and then we need to resolve the Package Manager dependencies? Go and delete them manually every time? This is really annoying.
     
    firstuser likes this.
  41. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,783
    Just went through the same thing and removing version control package sorted it out.

    But as asset store publisher this now makes it impossible for me to use Newtonsoft in anything that would go into the store.

    Pointing our customers to this forum would not stop the torrent of 1*'s we would get.
     
    CodeRonnie and grentle like this.
  42. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    150
    2 versions installed of the same project
    2020.3.1f1
    copied that project and went to:
    - 2020.3.15f2
    opened it up - after removing the library and bam got that error - the newer version which i get that error - has the newtonsoft in there. where its not in package cache in the other one
     
  43. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    150
    hmmm so i moved the com.unity.nuget.newtonsoft to ..\PlayerDataCache\ and relaunched - didnt have the newtonsoft package recreate in cache any longer - then i closed unity and then removed it again and still not recreating- even though everytime i removed it before it would just recreate it self when i relaunched - so confused but hey if it works i guess?!
     
  44. HyronXIII

    HyronXIII

    Joined:
    Aug 6, 2020
    Posts:
    1
    If this can help anybody, I solved the problem by:

    -removing the Newtonsoft dll/xml files from the folder using them in Assets (in my case Barebones, which had a copy of Newtonsoft.Json.dll in Networking/Plugins/Json.NET).

    -modifying in Assets/Barebones the Barebones.asmdef file. From editor you can modify it by checking "Override Reference" box to true, then include in "precompiled references"
    Newtonsoft.Json.dll
    . This broke a bit the plugin for me since now Barebones wouldn't find anymore "websocket-sharp.dll", but I just added that as well to the list of precompiled references and it worked.

    The principle should be the same with any other Asset in theory. You remove the dll and tell to the Asset to look somewhere else for the dll

    as extra section, my .asmdef file went from

    Code (JavaScript):
    1. "overrideReferences": false,
    2. "precompiledReferences": [],
    to

    Code (JavaScript):
    1. "overrideReferences": true,
    2. "precompiledReferences": [
    3.      "Newtonsoft.Json.dll",
    4.      "websocket-sharp.dll"
    5. ],
     
    CodeRonnie, tonialatalo and firstuser like this.
  45. madfu

    madfu

    Joined:
    Aug 9, 2018
    Posts:
    19
    So, i know this is an old post, but i just migrated my project which had been running successfully with 2019.4.28f1 to 2020.3.22f1 and ran into this issue. i knew it was coming: i have a number of hand-compiled libraries that are imported as plugins, and many use jilleJr's Newtonsoft.Json-for-Unity, which i also compile from source. from everything i have been able to gather, that version is also the one that Unity has been using as a model, but JilleJr's version is the most up-to-date.

    in any case, because i knew this bug was coming, i've been scouring the nets for some time for a reasonable solution that didn't require me to muck around too much in Unity's internals.

    this solution worked for me, full stop. my project was able to compile successfully.

    that it did, leaves me with some really uneasy questions. i've been on git for years, and have yet to have a single problem with it for SCM (Version Control), even for Unity. is there something so amazing about Unity's Version Control solution that it should be allowed to break builds across the entire ecosystem? what am i missing?

    also, the easiest solution to my mind would be to alter the namespace of Unity's version of Newtonsoft.Json to make it independent of the versions in use across the ecosystem. is there some reason that this isn't possible?

    not looking to pile onto Unity on this one, but if anyone has insight here, i'd love to hear it.
     
  46. wechat_os_Qy0y37P2iBclWzgwCRBR-gYGo

    wechat_os_Qy0y37P2iBclWzgwCRBR-gYGo

    Joined:
    Feb 1, 2020
    Posts:
    1
  47. HunterAhlquist

    HunterAhlquist

    Joined:
    Oct 6, 2013
    Posts:
    132
    Having this same problem, it appears Unity Collab is using JSON.NET as a dependency. Causing forks of JSON.NET like "Newtonsoft.Json-for-Unity" to conflict. This really sucks considering I use unity collab.
     
    ENOUGH- likes this.
  48. scappatura

    scappatura

    Joined:
    Oct 30, 2016
    Posts:
    7
  49. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hey, everyone. The latest version of the Version Control package (1.14.12 for Unity 2019LTS and 1.15.12 for Unity 2020LTS+) has removed its dependency on Unity's JSON package. This should address many of the issues most of you have had with trying to use a newer version of JSON while still using the Version Control package.

    Thank you all so much for your patience. We're very sorry for the frustrations this has caused and we will aim to do better in the future.
     
  50. UnityManuJack

    UnityManuJack

    Unity Technologies

    Joined:
    May 30, 2019
    Posts:
    11
    Hi,

    Update on the Newtonsoft package:
    • We are working on a Newtonsoft package update - com.unity.nuget.newtonsoft-json to support latest 13.0.1 by end of Q1
    • Package will support 2019.4 and up
    • To avoid assembly clashes, please use this package if you intend to use Newtonsoft Json
    • Long term, we are planning to officially support Newtonsoft by making it public in Package Manager and keep it in sync with Newtonsoft releases