Using Newtonsoft.Json in tests: "The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)" #39
-
Expected behaviorI expected to "using Newtonsoft.Json" to import the package. Actual behaviorThe "using Newtonsoft" line causes a compilation error: Assets/Tests/EditMode/DataTest.cs(6,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) Steps to reproduce
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using Newtonsoft.Json;
public class DataTest
{
[Test]
public void JsonIsReturned(){
var jsonString = "{\"$base\":14}";
var expectedInfo = JsonConvert.DeserializeObject<JiraData>(jsonString);
}
}
DetailsHost machine OS running Unity Editor 👉 Mac OS X 10.14.5 Unity build target 👉 Andriod/iOS Newtonsoft.Json-for-Unity package version 👉 12.0.201 I was using Unity version 👉 2019.2.13f1 Checklist
Thanks for your package and for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Ok. Closing, as this seems to be a Unity thing rather than something specific to this package. |
Beta Was this translation helpful? Give feedback.
-
Thanks for bringing this up. Yes it seems common to have to specify all references manually for testing assembly definitions. As said in the linked forum post you can solve it by clicking + on the references and selecting Newtonsoft.Json |
Beta Was this translation helpful? Give feedback.
-
Oh yes. I wasn't really getting that. In the info panel for the assembly definition file in (for me) the |
Beta Was this translation helpful? Give feedback.
-
Sometimes (depending on Unity version) disabling the "Override References" checkbox will then automatically reference it, like it does in any other asmdef. |
Beta Was this translation helpful? Give feedback.
Oh yes. I wasn't really getting that. In the info panel for the assembly definition file in (for me) the
/Assets/Tests/EditMode
folder. Thanks 🙏🏻