Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Newtonsoft error using PM

Discussion in 'Package Manager' started by ItzChris92, Oct 2, 2019.

  1. ItzChris92

    ItzChris92

    Joined:
    Apr 26, 2017
    Posts:
    299
    Hi,

    Not sure if this is the correct place to be posting this, but I was unsure where else it may belong.

    I'm getting this error when I try to use the Newtonsoft.Json namespace:

    error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?

    I have used Newtonsoft before, and believe I'm doing things correctly, but to no avail. I have thoroughly googled this error, and tried suggestions but the error still persists. I have tried installing older versions, I've triple checked my references. I'm baffled at the moment. Any help would be appreciated!
     
  2. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    143
    Hi @ItzChris92,

    I presume you're talking about the com.unity.nuget.newtonsoft-json package. Please note that this package is currently intended for internal use. For now it can only be referenced through the use of an Assembly Definition file by checking "Override References" on it, and adding the DLL as an explicit assembly reference. See the Backwards compatibility and implicit dependencies section of https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html for more info.
     
  3. ItzChris92

    ItzChris92

    Joined:
    Apr 26, 2017
    Posts:
    299
    Thanks. I also tried downloading newtonsoft and placing it in my plugins folder, but the same error appears
     
  4. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    143
    Oh, this might be a problem with the same assembly being present in the project multiple times - perhaps the Compilation Pipeline gets confused about which one to use, and only considers the Importer Settings for one of them (in the package). Did you try with the DLL, or the source code? You could try with the source code in your project (with or without an .asmdef to make it a separate assembly) and see if that works.
     
  5. ItzChris92

    ItzChris92

    Joined:
    Apr 26, 2017
    Posts:
    299
    I put the source code in the plugins folder. Is this correct or should it just be the correct dll file in there, and the reference added on VS? Then I imagine the source code would go in the packages folder for my project? I've not had much experience using dll files, but I did not seem to have any problems the last time I used newtonsoft. Apologies for the noob questions
     
    Last edited: Oct 3, 2019
  6. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    143
    Did you put that code/DLL in an Editor folder under Plugins? Otherwise your Editor code will not be able to access it.
     
  7. ItzChris92

    ItzChris92

    Joined:
    Apr 26, 2017
    Posts:
    299
    No i didn't. I thought that was only necessary for editor extensions.

    For the time being I have just installed the json. Net from the asset store. I'll come back and try again another time if I find there's a need for the newer versions of newtonsoft. Thanks for the replies
     
  8. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    143
    I'm sorry, You're right, I got confused for a moment. Indeed it doesn't have to be under an Editor folder since it's not accessing Editor APIs.

    So, I can't really say what's wrong in your case. Take a look at the Editor.log file, there may be hints. Otherwise I recommend opening a Bug report using Help > Report a Bug to get further personalized help.