Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

unity3d

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/[email protected]/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?

like image 879
Alde Avatar asked Oct 12 '20 15:10

Alde


Video Answer


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

like image 135
Mikhail Avatar answered Oct 11 '22 14:10

Mikhail


based on this answer: https://www.gitmemory.com/issue/juicycleff/flutter-unity-view-widget/414/859018825

best way is to import project without JsonDotNet folder or remove JsonDotNet folder before importing.

JsonDotNet folder

like image 38
Omid Fast Avatar answered Oct 11 '22 13:10

Omid Fast


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.

like image 40
user16189729 Avatar answered Oct 11 '22 13:10

user16189729