Photon conflicts with Json.Net for Unity

In my current project I have imported the Photon Unity Networking package and the Json.Net for Unity package from parentElement.

This causes the error: Assets/3rdPartyTools/Photon Unity Networking/Editor/PhotonNetwork/AccountService.cs(181,45): error CS0433: The imported type `Newtonsoft.Json.JsonConvert' is defined multiple times.

Removing the Newtonsoft.Json.dll from the Photon Unity Networking\Editor\PhotonNetwork folder fixes the build errors, but now I am getting:

A script behaviour has a different serialization layout when loading (Read 24 bytes but expected 64 bytes)
and
PhotonNetwork threw an exception. Type: System.TypeInitializationException

Json.Net for Unity doesn't use the Newtonsoft.Json.dll, so I can't just remove it to clear the conflict.

Has anyone else ever experienced this problem? How did you resolve it?

Comments

  • The error seems odd. Serialization layout? This sounds a bit like an issue with meta files or so. Try "re-import all" (right click on project / assets).

    In worst case, get rid of the AccountService.cs. It's the only place that uses Json and only needed by the Wizard Editor window, which is only used for initial registering of an account (where you enter your email).
    I hope you can do that refactoring on your own. Shouldn't be too difficult.
  • This occurs on Windows Store builds for Windows 8.1. This doesn't occur on PC Standalone builds. I have not attempted any other types of builds.

    I was able to reproduce the problem on a different machine, that never had Json.net installed. So, it looks like the problem is with Windows 8.
  • So it's a problem with the JSon dll in the player on Windows 8? I can imagine that being incompatible. It took some time to get our stuff Windows Store compatible.
    Maybe the lib has a special build for Win 8? Then you can put it in the \Assets\Plugins\Metro folder and it only gets inpo Win 8 players. This is a Unity feature we use, too.
  • sosh
    sosh
    edited June 2016
    I've just added Newtonsoft.json.dll to our assets dll folder, and I'm getting the same error (Windows 7)

    (Solved by deleting the dll from the PhotonUnityNetworking/Editor/PhotonNetowrk folder.)
  • This resolved my issue in 2017 after purchasing this:
    https://www.assetstore.unity3d.com/en/#!/content/11347

    This is still an issue -- I had to dig deep to find the solution here in this thread. Better if this was somehow managed in a different way to help others that my experience this.