Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thestonefox opened this issue Mar 24, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@thestonefox
Copy link
Member

thestonefox commented Mar 24, 2022

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" to Packages/manifest.json
  • Let Unity install Mono-Cecil package
  • Update Packages/manifest.json to include Tilia scoped registry
    • "scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org/", "scopes": [ "io.extendreality" ] } ],
  • Add any Tilia package to Packages/manifest.json e.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)
@thestonefox thestonefox added the bug Something isn't working label Mar 24, 2022
@thestonefox
Copy link
Member Author

thestonefox commented Mar 24, 2022

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.json to include Tilia scoped registry
    • "scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org/", "scopes": [ "io.extendreality" ] } ],
  • Add any Tilia package to Packages/manifest.json e.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" to Packageds/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

@thestonefox
Copy link
Member Author

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" to Packages/manifest.json
  • Let Unity install Mono-Cecil package
  • Update Packages/manifest.json to include Tilia scoped registry
    • "scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org/", "scopes": [ "io.extendreality" ] } ],
  • Add "io.extendreality.malimbe": "9.7.0" to Packages/manifest.json
  • Let Unity install Malimbe package
  • Add FodyWeaver.xml file to Assets
<?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 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
Copy link
Member Author

@thestonefox
Copy link
Member Author

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.sln in Visual Studio to access the Malimbe code project
  • Run a Release build in Visual Studio and the output will go to Sources/UnityPackaging/bin/Release
  • Copy the package.json file from the root directory into the Sources/UnityPackaging/bin/Release directory
  • 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",

@thestonefox
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

@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
Copy link
Member Author

@thestonefox
Copy link
Member Author

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
Copy link
Member Author

thestonefox commented Mar 26, 2022

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

@thestonefox
Copy link
Member Author

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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant