Unity errors when two packages that use Mono Cecil are imported

984 Views Asked by At

I have adopted the maintenance of a weaver package for Unity called Malimbe:

https://github.com/ExtendRealityLtd/Malimbe

Which weaves code to replace tags to remove common boilerplate.

Malimbe uses Fody 3.5.5 which in turn uses Mono.Cecil and then Malimbe itself seems to hook into the reference of Mono Cecil that Fody is using so it can further utilise it.

When Malimbe builds it includes the Mono.Cecil dlls in the release Editor folder.

The issue now is when another Unity package uses Mono.Cecil such as com.unity.netcode.gameobjects (https://github.com/Unity-Technologies/com.unity.netcode.gameobjects) which uses the Unity package version of Mono Cecil (which is 0.10)

if both of these packages are in the Unity project then Unity errors complaining of an infinite loop and that the version of Mono Cecil used by Malimbe is out of date (probably due to the one being included in Fody 3.5.5 being quite old)


The process of causing the error is to:

  • Include unity's version of Mono Cecil in the project first (e.g. by adding the netcode package or simply the unity Mono Cecil package directly)
  • Then include a package that relies on Malimbe and requires some weaving

This will cause the error to occur

However, if the package that relies upon Malimbe to weave it is included first then the package that uses Unity's Mono Cecil is included then no error occurs.

I'm assuming its something to do with Unity is only loading in 1 version of Mono Cecil and if it loads the Malimbe one first then because its old, everything can use it...


I'm at a loss of how to fix the issue within Malimbe.

I've tried updating Fody to the latest version 6.6.0, but that includes a later version of Mono Cecil (0.11) which in the first instance still clashes with Unity, but more so the update of Fody causes more fundamental issues due to changes in Fody that there isn't any documentation around to address the update

For instance, WeaverEntry used to contain an AssemblyName field which was being used in Malimbe to ensure multiple assemblies of the same name weren't being loaded in but there does not seem to be a replacement for it. There is AssemblyBaseName but this is a property and also does not seem accessible from the Malimbe code for some reason.


For a specific detail of the issue, I raised this bug on the Malimbe GitHub page:

https://github.com/ExtendRealityLtd/Malimbe/issues/72

Plus there is a bountysource bug bounty for it if anyone can resolve it:

https://app.bountysource.com/issues/106260245-infinite-loop-on-import-into-unity-if-another-version-of-mono-cecil-is-already-included-in-project

0

There are 0 best solutions below