ExtendRealityLtd / Malimbe

[Obsolete - No longer maintained] A collection of tools to simplify writing public API components for the Unity software.
MIT License
51 stars 11 forks source link

Infinite loop on import into unity if another version of Mono Cecil is already included in project #72

Open thestonefox opened 2 years ago

thestonefox commented 2 years ago

Environment

Not Recreatable in:

Steps to reproduce

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)
thestonefox commented 2 years ago

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.

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

thestonefox commented 2 years ago

Another way of recreating is:

^Assembly-CSharp
* Create a test c# script in the `Assets` directory 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)

thestonefox commented 2 years ago

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

thestonefox commented 2 years ago

Steps for building against a local copy of Malimbe

thestonefox commented 2 years ago

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 🤞

thestonefox commented 2 years ago

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?

thestonefox commented 2 years ago

@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 😄

thestonefox commented 2 years ago

Stackoverflow post: https://stackoverflow.com/questions/71613966/unity-errors-when-two-packages-that-use-mono-cecil-are-imported

thestonefox commented 2 years ago

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

thestonefox commented 2 years ago

If a solution isn't found then the only alternative will be to remove Malimbe from all Tilia packages and Zinnia.

Pros

Cons

thestonefox commented 2 years ago

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.

thestonefox commented 2 years ago

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