-
Notifications
You must be signed in to change notification settings - Fork 131
Assembly not found by my DLL. Wrong strong name identity of assembly #7
Comments
Hi @tarasov65536. This is an issue I hoped not to be needed to handle yet. But here goes. The versioning is irrelevant in this case. It would if your dll requires newtonsoft.json 12.0.0 and I supply 12.0.1. But that's not what's causing the issue. Problem is that the official Newtonsoft.Json you use from NuGet is compiled as a strongly named assembly with a key pair with public key token I've yet not found a good way to reference an assembly without the strong name. Maybe possible. In a different project of mine I did a workaround where I referenced the Will revisit if I find better solution. Maybe it's staring me in the eye. |
Solution found Came over this blog post, actually written by a teacher of mine, Fredrik Haglund, about setting the key of an assembly without access to the private key: https://blog.fredrikhaglund.se/blog/2009/02/06/how-to-patchfixhack-someone-elses-assembly/ With some testing where I applied the technique on the Newtonsoft.Json-for-Unity package build and ran the test suite inside Unity, it seems to work marvels! Unity doesn't seem to verify the assembly strong names at all. Not by the Mono compiler and not by the IL2CPP compiler. About IL2CPP, I've been able to dig up something from my emails that is of value; a response from an issue report to Unity I did the start of this year regarding signed assemblies:
However, about Mono, I'm unsure about it's capabilities on checking the DLL's. Maybe even anti-virus might grab it on some system scan. Have gotten it to build and run. Also tried using official Google.Apis.Core 1.42.0 inside the Unity project and it built correctly (once I had the correct versions setup) and was able to use Newtonsoft.Json via Google.Apis.Core in a test build with both Mono and IL2CPP. Now off to deploying it. These are important changes! |
This is fixed in version 12.0.102. The package will have a weak sign of the same public key used in the official Newtonsoft.Json. This means, from 12.0.102 and forth, you target the official Newtonsoft.Json in your class libraries when building, then you use Newtonsoft.Json-for-Unity in Unity. The workflow should be seamless. Note: Due to Unity not supporting Binding Redirects you can only use Newtonsoft.Json-for-Unity (this project) when targeting the same major as I've released. Meaning only 12.0.1, 12.0.2, 12.0.3 etc. will work, but 11.0.1, 10.0.1, 9.0.1 (and soon 13.0.1) etc does not work. For that you'll have to wait for me to release a backport to 11.0.1 and so forth. Excuse the wait, xmas times you know :) |
Expected behavior
I have dotnet core library that uses Newtonsoft.Json 12.0.1 as dependency. I want to use that library in my unity project. I installed Newtonsoft.Json-for-Unity with package manager and added dll with my library to Assets/Plugins folder of my unity project.
Actual behavior
When I try to use any classes from my library it says:
error CS0012: The type 'JsonSerializer' is defined in an assembly that is not referenced. You must add a reference to assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.
As I understand AssemblyVersion for original Newtonsoft.Json is always set to 12.0.0.0, but AssemblyVersion of Newtonsoft.Json-for-Unity is set to 12.0.1.0
Steps to reproduce
The text was updated successfully, but these errors were encountered: