Skip to content

Weaver fails to weave properly on 6.6/6.7 #4117

Description

@TheTechWiz5305

Describe the bug
On 6000.6.0b1 and 6000.7.0a1 (doesn't appear in 6000.5.1f1), Weaver fails to complete due to some change in the ILPP system that I cannot fully figure out. More details and findings below.

[IMPORTANT] How can we reproduce the issue, step by step:

  1. Create brand new 3D URP project with either 6000.6.0b1 or 6000.7.0a1.
  2. Once open, import Mirror v96.10.3.
  3. Error shown about how Mono.CecilX cannot be found.

Expected behavior
Weaver completes successfully with no issues or errors visible.

Screenshots
Image
Mono.CecilX Error.txt

Desktop (please complete the following information):

  • OS: Windows 11 64-bit (26200.8737)
  • Build target: Android
  • Unity version: 6000.7.0a1
  • Mirror branch: master

The workaround I came up with:
I want to bring up that I found a workaround, and in fact, does work on 2021.3.29f1 through 6000.7.0a1 when I tested.
It involves deleting Mono.CecilX which I know I shouldn't do because of the stack overflow bug from years ago, so I need some input on this for other ideas of tackling this.

Here's what I figured out:

  1. Delete Assets/Mirror/Plugins (which contains Mono.CecilX)

  2. Open up Visual Studio or another IDE, and open Find and Replace (In VS 2022/2026, this is Ctrl + Shift + F > Replace in Files)

  3. For "Find", put using Mono.CecilX, and for "Replace", put using Mono.Cecil. Make sure "Look in" (or IDE equivalent) is set to "Entire solution". Now, hit "Replace All".

  4. Minimize your IDE for a bit. Next, we want to open Unity's Package Manager. In the PM, hit the "+" (Plus) icon in the upper left, hit "Install package by name...", then in the name box, put in com.unity.nuget.mono-cecil.

  5. If you have errors about Cecil not existing in the namespace Mono still, in the search box of the project window, put in Unity.Mirror.CodeGen, click on the Assembly Definition, and under "Assembly References", add Mono.Cecil.dll and Mono.Cecil.Rocks.dll. This should fix those compiler errors.

  6. Now, go back to the project window, and this time, search for ILPostProcessorHook. Double-click on the C# script to open it in your IDE.

  7. In the script, find the method Process. Paste the code below at the top of the method, just before the "Processing {compiledAssembly.Name}" log:

    bool relevant = compiledAssembly.Name == MirrorRuntimeAssemblyName ||
                    compiledAssembly.References.Any(filePath => 
                        Path.GetFileNameWithoutExtension(filePath) == MirrorRuntimeAssemblyName);
    if (!relevant) 
        return new ILPostProcessResult(compiledAssembly.InMemoryAssembly, Log.Logs);

    Save the script once pasted.

  8. Finally, go back to the Project window of Unity, and this time search for Helpers. Open the script that shows up and is in Assets/Mirror/Editor/Weaver/Helpers. Delete the contents of the UnityEngineDllDirectoryName method. In its place, put the following code:

    string path = Assembly.GetExecutingAssembly().GetLoadedAssemblyPath();
    return Path.GetDirectoryName(path);

    Save the script, and you're done!

Additional Context:
Here is a sample project of what it should be like when the workaround is done. The project is Unity version 6000.6.0b1.
Also, some of this is likely a Unity Bug that hasn't been discovered yet, so if you find something abnormal with this, please tell me and I will create a Unity bug report!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions