Search Unity

[updated] How to reference Newtonsoft.json without conflicts?

Discussion in 'Entity Component System' started by jdtec, Feb 19, 2020.

  1. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    302
    [EDIT - the original error appears to stem from a Newtonsoft.json conflict, new issue continued on next post]

    I have hundreds of warnings which lead to errors like the one below on upgrading to the latest DOTs packages. Have tried deleting the Library folder and a few other things but can't seem to get rid of them.

    I'm using 2019.3.1f1

    Does anyone know why this happens and how to fix?

    Code (CSharp):
    1. Script 'Packages/com.unity.entities/Unity.Entities.CodeGen/LambdaJobs/InjectAndInitializeEntityQueryField.cs' will not be compiled because it exists outside the Assets folder and does not to belong to any assembly definition file.
    2. UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:396)
     
    Last edited: Feb 19, 2020
  2. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    302
    I fixed it by removing Newtonsoft.json and deleting the Library folder again. I noticed there is a Newtonsoft.json in Packages, however I can't reference this in my scripts for some reason.
     
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Unity silently added newtonosft.json to their package and it is set to not "auto reference". So the only solution is that enabling assembly definition for your all source code and use "override reference" option to use Unity's newtonsoft.json library.
     
    redfox_99, jhocking and jdtec like this.
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    The other option is move the newtonsoft package into the Packages folder in your project. That makes it a 'development' package. And then just copy in the dll version that you want, although it probably should be a newer version. You have to go through that process every time the newtonsoft package itself is updated, but it is a supported workflow and the one that solves the problem in the most direct way. Assembly def's are really not the correct solution to this even if they happen to work for your specific project.

    Edit: FYI you can once the package is in development change the assembly def settings if you need to. Although that's probably not the right choice in most cases.
     
    Last edited: Feb 19, 2020
    CodeRonnie and jdtec like this.
  5. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
  6. jdtec

    jdtec

    Joined:
    Oct 25, 2017
    Posts:
    302
    Thanks guys. I went with adding an assembly def file in the end.