7

Fix: after setting up a new MRTK3 project Newtonsoft.Json is missing

 1 year ago
source link: https://localjoost.github.io/Fix-after-setting-up-a-new-MRTK3-project-NewtonsoftJson-is-missing/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Joost van Schaik

Senior Mixed Reality Software Architect. Windows Development MVP. Mixed Reality, HoloLens, Unity, .NET, Azure

Fix: after setting up a new MRTK3 project Newtonsoft.Json is missing

2 minute read

If you are like me, you never even think about it. Newtonsoft.Json is like the hammer in your toolbox, the knife in your kitchen drawer: it’s always there in MRTK projects - and it’s a long time since I even thought about that. Until I recently set up a new MRTK3 project (pre-11) and it was not. Why?

That’s whyPermalink

My initial thought was a breaking change in the MRTK3 dependency chain, but I was wrong. You see, apparently the only MRKT3 module - or feature as the MRTK Feature tool calls it - that has a dependency on Newtonsoft.Json is the “MRTK Data Binding and Theming Early Preview” (com.microsoft.mrtk.data).

dataval.png

The MRTK Feature Tool actually tells you so, if you click the blue “(Details)” link and scroll down:

details.png

This wisdom you can also find in the generated file packages-lock.json in the packages folder of your product, after you installed the “MRTK Data Binding and Theming Early Preview”

packlock.png

This is the only occurrence of the com.unity.nuget.newtonsoft-json package. So, Long story short: if you don’t install “MRTK Data Binding and Theming Early Preview” package, you don’t get com.unity.nuget.newtonsoft-json and you can - just like me - spend an aggravating fifteen minutes trying to think why the Newtonsoft.Json namespace does not get resolved in your code.

Solution 1Permalink

Install “MRTK Data Binding and Theming Early Preview”, even if you are not using it. Done. A bit of a heavy-handed approach, but it works.

Solution 2Permalink

If you don’t plan on using the “MRTK Data Binding and Theming Early Preview”, the most efficient way, of course, is to install the Newtonsoft.Json yourself. This is where the fun begins. Where Visual Studio has NuGet, Unity has the package manager. I sometimes think the Unity Package Manager is especially designed to drive developers insane. First of all, you have to give a scope where to search:

packman.png

Why there no “everywhere” option for search, you ask? Yeah, beats me too. But now comes the real kicker: if you search in all four options, none of them yield anything when you search for NewtonSoft.Json.

So in the end I got sick and tired of it, and manually added one line to the dependencies in the manifest.json (also in your project’s Packages folder) to see if that would work.

add.png

And lo and behold, now it appears in the package manager and it even helpfully tells you there’s a newer version:

packman2.png

Concluding wordsPermalink

Maybe I am missing something here, but I have not found a more intuitive way to do this (or any other way, for what matters). I love Unity, but sometimes things are very illogical or hard to find. Anyway, no project to go with this blog as there is no code to share.

Tags: HoloLens2 MRTK3 Unity Windows Mixed Reality

Updated: October 22, 2022

Previous Next

Comments

You can view the comments on GitHub.

You May Also Enjoy


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK