简体   繁体   中英

Error CS0246: The type or namespace name 'Newtonsoft' could not be found

Full error: Assets\\Scripts\\ProjectsScript.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?)

When run through Unity, the app works as expected. However, when trying to build the app in Unity to export it to a Magic Leap using the Lumin platform, it fails because of the mentioned compiler error. There is a JsonDotNet folder containing the appropriate files under the Assets folder. Settings under Project Settings->Player->Other settings seem to be appropriately set (Scripting Runtime Version -> .NET 4.X Equivalent) (Api Compatibility level -> .NET 4.x). In visual studio -> manage nuget solutions, json.net is found. I know there are similar questions, but we have been trying their solutions, to no avail. We have also tried moving around the JsonDotNet folder but unity still can't seem to find it at compile time.

The simplest solution is to copy the file Newtonsoft.Json.dll to your Assets folder, then remove the dependency on the Nuget package and reference the copied DLL instead. Unity will pick up the presence of the new DLL and all the code within the unity project will automatically reference it.

An alternative is to use json.net by newtonsoft from the Asset store (free), but I opted for the former way because I wanted my external DLLs (not part of the Unity project, compiled into the Assets folder) to reference the same version of json.net.

hth

The Answer is JsonDotNet is not officially supported on MagicLeap. Even though the Unity Asset Store says it officially supports all versions except blah blah, however the asset was posted in 2017 before Lumin was an official platform. We need to petition Newtonsoft to update their Unity asset.

The question here states "newtonsoft could not be found...also tried moving around the JsonDotNet folder..."
The stackoverflow "answer" here states "The simplest solution is to copy the file Newtonsoft.Json.dll to your Assets folder...an alternative is use json.net by newtonsoft... but I opted for the former..."

So according to that, if I am to understand correctly: The problem is X. The answer poster says the simplest solution is X, and the alternative solution is X. The answer poster opted for X.

Stack Overflow ftw. Maximum effort dfl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM