Unity "Multiple precompiled assemblies with the same name" using external dll

Viewed 31890

I have a "Shared" project where I share code between my client (unity) and my server (C# server)

Both projects require Newtonsoft.Json.dll


When I compile the Shared.dll and put it inside of Unity's Resources folder (so it's included in the build), I get this error :

PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included or the current platform. Only one assembly with the same name is allowed per platform. Assembly paths: 
Assets/Resources/Shared/Newtonsoft.Json.dll
C:/Users/rotmg/Documents/GitHub/AG-LNL/AG-LNL-Client/Library/PackageCache/com.unity.nuget.newtonsoft-json@2.0.0-preview/Runtime/Newtonsoft.Json.dll

I realise it's a conflict between Unity's dependency on Newtonsoft.Json and my Shared.dll's.


This answer :

https://answers.unity.com/questions/1697304/how-to-resolve-multiple-precompiled-assemblies-err.html

Says to use "merge all the dependencies into one .dll"

So I tried using Costura.Fody to build a single .dll that bundles all dependencies, but then I get an error saying that I should add references to the dependencies that Shared has. (NLog, BouncyCastle, etc.)


How can I resolve this conflict?

3 Answers

In my case after updating from Unity 2020.3.8f1 to 2020.3.17f1 and package com.unity.collab-proxy from 1.3.9 to 1.7.1 it got dependency com.unity.nuget.newtonsoft-json which was conflicting with my manually imported JsonDotNet package in Assets folder.

enter image description here

enter image description here

Removing my manually imported JsonDotNet package from Assets folder helped. After removing close Unity, delete folders YouProjectFolder\Library\PackageCache and YouProjectFolder\Library\ScriptAssemblies and restart Unity.

enter image description here

I got this issue after adding another package using Newtonsoft.Json.dll, causing a conflict. For me removing one of the duplicates resolved the issue.

Related