Malimbe
Malimbe copied to clipboard
Infinite loop on import into unity if another version of Mono Cecil is already included in project
Environment
- Code source: GitHub
- Code version: 9.7.0
- Platform version: 2020.2.7f1
- 3rd party dependencies:
"com.unity.nuget.mono-cecil": "1.10.1"
Not Recreatable in:
- Unity 2019.4.36f1
- Unity 2020.1.17f1
Steps to reproduce
- Create a new Unity project in 2020.2.7f1 or above
- Add
"com.unity.nuget.mono-cecil": "1.10.1"toPackages/manifest.json - Let Unity install Mono-Cecil package
- Update
Packages/manifest.jsonto include Tilia scoped registry"scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org/", "scopes": [ "io.extendreality" ] } ],
- Add any Tilia package to
Packages/manifest.jsone.g. add"io.extendreality.tilia.camerarigs.trackedalias.unity": "1.9.0", - Let Unity install Tilia package
Note: You can just add Zinnia instead of a Tilia package to get the error:
"io.extendreality.zinnia.unity": "1.47.1",Just adding Malimbe"io.extendreality.malimbe": "9.7.0"isn't enough to get the error because no code is being weaved via Malimbe.
The problem is compounded when using a Unity package like "com.unity.netcode.gameobjects": "1.0.0-pre.6", as it has a dependency on the Unity version of Mono Cecil and will always pull in that third party dependency.
Expected behavior
All packages should install correctly
Current behavior
The Malimbe version of Mono Cecil is older than the current Unity installed version and therefore throws a bunch of errors then gets stuck in an infinite loop trying to import assets
The weaver assembly 'Malimbe.BehaviourStateRequirementMethod.Fody, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' references an out of date version of Mono.Cecil.dll. Expected strong name token of '50-CE-BF-1C-CE-B9-D0-5E' but got '1C-A0-91-87-7D-12-CA-03'. The weaver needs to update to at least version 3.0 of FodyHelpers.
UnityEngine.Logger:Log (UnityEngine.LogType,object)
Malimbe.FodyRunner.UnityIntegration.Logger:Log (Malimbe.FodyRunner.LogLevel,string)
Malimbe.FodyRunner.LogForwarder:Log (Malimbe.FodyRunner.LogLevel,string)
Malimbe.FodyRunner.LogForwarder:LogError (string)
ExceptionExtensions:LogException (ILogger,System.Exception)
InnerWeaver:Execute ()
Malimbe.FodyRunner.Runner/<>c__DisplayClass6_0:<RunAsync>b__0 ()
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
An infinite import loop has been detected. The following Assets were imported multiple times, but no changes to them have been detected. Please check if any custom code is trying to import them:
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/HowToGuides/AddingATrackedAlias/assets/images/TrackedAliasInSceneWithExampleAvatarObjects.png(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.zinnia.unity/package.json(modified date 2022-03-15T20:42:31.9119998Z)
Packages/io.extendreality.zinnia.unity/Runtime/Data/Operation/Extraction/GameObjectExtractor.cs - (Force Reimport)(modified date 2022-03-15T20:42:31.9119998Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/API/TrackedAliasFacade.LinkedAliasAssociationCollectionUnityEvent.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/API/TrackedAliasConfigurator.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Runtime/SharedResources/Scripts/TrackedAliasFacade.cs - (Force Reimport)(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/HowToGuides/AddingATrackedAlias/assets/images/DragAndDropSpatialSimulatorIntoTrackedAlias.png(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/LICENSE.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/docfx.json(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Editor/Utility/PrefabCreator.cs - (Force Reimport)(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.malimbe/package.json(modified date 2021-11-30T09:23:25.704Z)
Packages/io.extendreality.malimbe/README.md(modified date 2021-11-30T09:23:25.704Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/package.json(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.zinnia.unity/CHANGELOG.md(modified date 2022-03-15T20:42:31.9119998Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/CHANGELOG.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.malimbe/LICENSE.md(modified date 2021-11-30T09:23:25.704Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Runtime/Prefabs/CameraRigs.TrackedAlias.prefab(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/API/TrackedAliasFacade.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/README.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/HowToGuides/AddingATrackedAlias/README.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/API/README.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/HowToGuides/AddingATrackedAlias/assets/images/DragAndDropUnityXRIntoTrackedAlias.png(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/FodyWeavers.xml(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.zinnia.unity/README.md(modified date 2022-03-15T20:42:31.9119998Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/HowToGuides/AddingATrackedAlias/assets/images/UpdateTrackedAliasElementsSize.png(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/HowToGuides/AddingATrackedAlias/assets/images/DisableUnityXRGameObject.png(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.malimbe/THIRD_PARTY_NOTICES.md(modified date 2021-11-30T09:23:25.704Z)
Packages/io.extendreality.malimbe/CHANGELOG.md(modified date 2021-11-30T09:23:25.704Z)
Packages/io.extendreality.zinnia.unity/FodyWeavers.xml(modified date 2022-03-15T20:42:31.9119998Z)
Packages/io.extendreality.tilia.camerarigs.trackedalias.unity/Documentation/HowToGuides/Installation/README.md(modified date 2022-03-22T15:35:24.842Z)
Packages/io.extendreality.zinnia.unity/LICENSE.md(modified date 2022-03-15T20:42:31.9119998Z)
Packages/io.extendreality.zinnia.unity/Editor/Data/Collection/ObservableListEditor.cs - (Force Reimport)(modified date 2022-03-15T20:42:31.9119998Z)
Workaround
If you install the Tilia packages before installing any other package that uses the Unity version of Mono Cecil then it works as expected.
- Update
Packages/manifest.jsonto include Tilia scoped registry"scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org/", "scopes": [ "io.extendreality" ] } ],
- Add any Tilia package to
Packages/manifest.jsone.g. add"io.extendreality.tilia.camerarigs.trackedalias.unity": "1.9.0", - Let Unity install Tilia package
- Add
"com.unity.nuget.mono-cecil": "1.10.1"toPackageds/manifest.json - Let Unity install Mono-Cecil package
This is not ideal as it means any tilia package added after the Unity Mono Cecil has been added will cause the issue
Issue
This workaround still fails when running a build
Another way of recreating is:
- Create a new Unity project in 2020.2.7f1 or above
- Add
"com.unity.nuget.mono-cecil": "1.10.1"toPackages/manifest.json - Let Unity install Mono-Cecil package
- Update
Packages/manifest.jsonto include Tilia scoped registry"scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org/", "scopes": [ "io.extendreality" ] } ],
- Add
"io.extendreality.malimbe": "9.7.0"toPackages/manifest.json - Let Unity install Malimbe package
- Add
FodyWeaver.xmlfile toAssets
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Malimbe.FodyRunner>
<AssemblyNameRegex>^Assembly-CSharp</AssemblyNameRegex>
</Malimbe.FodyRunner>
<Malimbe.BehaviourStateRequirementMethod/>
<Malimbe.MemberChangeMethod/>
<Malimbe.MemberClearanceMethod/>
<Malimbe.PropertySerializationAttribute/>
<Malimbe.XmlDocumentationAttribute IdentifierReplacementFormat="`{0}`"/>
</Weavers>
- Create a test c# script in the
Assetsdirectory to use the weaver
using Malimbe.PropertySerializationAttribute;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
[Serialized]
public string MyProp { get; set; }
}
- This will create the same infinite loop error
An infinite import loop has been detected. The following Assets were imported multiple times, but no changes to them have been detected. Please check if any custom code is trying to import them:
Assets/Test.cs - (Force Reimport)(modified date 2022-03-24T09:43:45.2738359Z)
I've raised a BountySource for this one as it's beyond me
https://app.bountysource.com/issues/106260245-infinite-loop-on-import-into-unity-if-another-version-of-mono-cecil-is-already-included-in-project
Steps for building against a local copy of Malimbe
- Git clone the Malimbe repo to a local drive
git clone https://github.com/ExtendRealityLtd/Malimbe.git - Open
Sources/Malimbe.slnin Visual Studio to access the Malimbe code project - Run a
Releasebuild in Visual Studio and the output will go toSources/UnityPackaging/bin/Release - Copy the
package.jsonfile from the root directory into theSources/UnityPackaging/bin/Releasedirectory - Create a Unity project and update the manifest.json to point to this local package
"io.extendreality.malimbe": "file://<path-to-project>/Sources/UnityPackaging/bin/Release",
I've raised a bug with Unity on this issue as well just on the off chance its an issue with Unity and not a problem with Malimbe 🤞
Not sure if its possible to pack the FodyHelpers and it's version of Mono.Cecil away so it doesn't create a clash
using something like: https://github.com/peters/ILRepack.MSBuild.Task
I have tried this but couldn't get it to work, maybe someone else would have better luck?
@bddckr I know you don't have the time these days, but I'm totally stumped on this one. I've tried everything within my limited knowledge to try get it to work from updating Fody to 6.6.0 (which then has additional issues as things like AssemblyName has been removed since 3.5.5)
to including the latest version of Mono Cecil in Malimbe, but no matter what I do, it just falls over in some area.
Totally understand if you don't have time to view or reply, but I thought it would be worth asking the question anyway 😄
Stackoverflow post: https://stackoverflow.com/questions/71613966/unity-errors-when-two-packages-that-use-mono-cecil-are-imported
A potential solution I think could be to merge the Mono Cecil dlls into the relevant dlls that rely upon it, then technically Mono Cecil won't need to be included with Malimbe.
Need to investigate if this is feasible and possible and what dlls actually rely on Mono Cecil
If a solution isn't found then the only alternative will be to remove Malimbe from all Tilia packages and Zinnia.
Pros
- Removal of Mono Cecil dependency which will remove any crashes
- No reliance on code weaving that can potentially break with Unity in the future
Cons
- The codebase will become more verbose with more boilerplate code being added
- The custom Unity inspector will be removed and may therefore stop updates to properties in the inspector being run
I'm in the process of removing Malimeb from Zinnia
This is the branch that will become the final pull request:
https://github.com/ExtendRealityLtd/Zinnia.Unity/tree/feat/remove-malimbe
Malimbe also needs removing from all Tilia packages
I cannot work out why this issue is occurring, so I'm going to just remove the dependency as its more trouble than its worth.
This is still a going concern in Malimbe but no longer an issue for Zinnia or Tilia packages as now Malimbe has been removed as a dependency