Could you please help me to solve the issue with assembly referencing.
I’m using Mono.Cecil.dll for postprocessing.
If I add this assembly to project, then I get the following error on machine where Unity installation contains Mono.Cecil.dll in C:/Program Files/.../Editor/Data/Managed/ directory (it is installed along with Windows Store Apps support):
error CS1703: An assembly `Mono.Cecil' with the same identity has already been imported. Consider removing one of the references
Assets/Editor/.../Mono.Cecil.dll (Location of the symbol related to previous error)
C:/Program Files/.../Editor/Data/Managed/Mono.Cecil.dll (Location of the symbol related to previous error)
If I remove this assembly from project, then I get the following error on machine where Unity installation does not contain Mono.Cecil.dll in .../Editor/Data/Managed/ directory (it is not installed by default):
error CS0234: The type or namespace name `Cecil' does not exist in the namespace `Mono'. Are you missing an assembly reference?
How to fix this issue so that project could build in both configurations?
We don’t have a great solution for this issue at the moment. The problem is indeed that Unity can ship with Mono.Cecil.dll for internal use. At the moment, we have a change in process to rename Mono.Cecil.dll used in Unity to Unity.Cecil.dll, so the conflict will be avoided. This change won’t make it into the 2017.1 version of Unity though.
Until then, I would recommend building Mono.Cecil yourself, and renaming it. The Mono.Cecil build process has a built-in process for creating it with a different name to avoid situations just like this.
Thanks! I will try this workaround, if I can resolve the second problem mentioned in this thread. Namely: modifying “Library/ScriptAssemblies/Assembly-CSharp.dll” does not have effect while building actual player for Android. Could you please give some comments on this?
Renaming doesn’t help since name clashes still exist between assemblies with different identities (names, versions, signatures).
error CS0433: The imported type `Mono.Cecil.TypeDefinition' is defined multiple times
It has no methods for generating alternative root namespace instead of Mono.Cecil like MyCompany.Cecil. Just ordinary MSBuild-scripts: https://github.com/jbevain/cecil
Maybe there is not a good solution then until we sort this out on our end then. Hopefully that will make the 2017.2 release of Unity.
Also, we don’t have a hook for modify Assembly-CSharp.dll at the time you want. I’m hearing that something is in the works for that as well, but I don’t have a timeline.
At second glance this doesn’t sound like good idea (not to mention that simple assembly renaming doesn’t work). I mean, if these are your internal details, how do they even mixed with user’s code? It does not make sense. For example, when Visual Studio, or Xamarin Studio, or ReSharper use some well known third-party libraries like NUnit or JSON.NET internally, this fact has no chance to break user’s code, which also happens to use these libraries.
You probably should deeply reconsider separation of your own dependencies from user’s dependencies in natural way, this does not need renaming all third party tools. Mono.Cecil referenced by your toolset should not interfere with Mono.Cecil referenced by user. Just place it in your private folder that is not in search path for resolving user’s dependencies.
I’ve learned a bit more about this issue. You are indeed correct, the proper thing to do it not put the Mono.Cecil.dll in a directory where it will conflict. From what I can tell, that only happens for the Windows Store player build with IL2CPP. We have an existing bug report for this issue, and we are looking to correct it now.
I got the same problem, I want to use Mono.Cecil in my editor code, but I can’t reference it, and I installed Mono.Cecil package with package manager. I just dont know how to using it, always got missing Assembly reference error.
I’m using 2019.2.6f1 Mac version, in visual studio mac I cannot using Mono.Cecil, if I add Mono.Cecil dll manually in csproj, visual studio can using Mono.Cecil but unity will not compile and always says missing reference.