Harmony icon indicating copy to clipboard operation
Harmony copied to clipboard

PatchFunctions.UpdateWrapper NotImplementedException on MacOS

Open AqlaSolutions opened this issue 1 year ago • 10 comments
trafficstars

This exception occurs when launching from Rider: image

We don't have this problem on Windows or inside asp.net linux docker containers.

The exception occurs even when launching without debugging.

The patch code:

[HarmonyPatch(typeof(ClassName), "MethodName")]
[UsedImplicitly]
static class Patch
{
    [UsedImplicitly]
    [HarmonyPrefix]
    static bool Prefix(ClassName __instance)
    {
        if (__instance.Property is AnotherClass { AnotherProperty: true })
            return false;
        return true;
    }
}

Runtime environment (please complete the following information):

  • OS: MacOS Ventura 13.3.1 (a)
  • .NET version 7.0.402
  • Harmony version 2.3.3 (thin)

Our host application is ASP.NET Web Api app.

AqlaSolutions avatar Apr 17 '24 11:04 AqlaSolutions

Does this happen with the non-thin version too? If so, you are not supplying the correct dependencies.

pardeike avatar Apr 17 '24 12:04 pardeike

For reference, I am as I type, using Harmony 2.3.3 on my MacBook Air M2 with RimWorld just fine.

pardeike avatar Apr 17 '24 12:04 pardeike

The non-thin version doesn't work for us (exception when debugging from Rider on Windows). https://github.com/pardeike/Harmony/issues/585

What are the dependencies? The docs mentions that one may need to add them but what exactly to add?

AqlaSolutions avatar Apr 17 '24 12:04 AqlaSolutions

If you use an IDE (like Visual Studio, don’t know about Rider, never used it) it will automatically download the dependencies. The nuget package also lists the dependencies as does a decompiler like dnSpy

pardeike avatar Apr 17 '24 12:04 pardeike

These are nuget package dependencies:

<dependencies>
  <group targetFramework=".NETFramework3.5">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
  </group>
  <group targetFramework=".NETFramework4.5.2">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
  </group>
  <group targetFramework=".NETFramework4.7.2">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
  </group>
  <group targetFramework=".NETFramework4.8">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
  </group>
  <group targetFramework=".NETCoreApp3.0">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
  </group>
  <group targetFramework=".NETCoreApp3.1">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
  </group>
  <group targetFramework="net5.0">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
    <dependency id="System.Text.Json" version="5.0.2" exclude="Build,Analyzers" />
  </group>
  <group targetFramework="net6.0">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
    <dependency id="System.Text.Json" version="6.0.9" exclude="Build,Analyzers" />
  </group>
  <group targetFramework="net7.0">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
    <dependency id="System.Text.Json" version="7.0.4" exclude="Build,Analyzers" />
  </group>
  <group targetFramework="net8.0">
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
    <dependency id="System.Text.Json" version="8.0.1" exclude="Build,Analyzers" />
  </group>
  <group targetFramework=".NETStandard2.0">
    <dependency id="Lib.Harmony.Ref" version="2.3.3" exclude="Build,Analyzers" />
    <dependency id="MonoMod.Core" version="1.1.0" exclude="Build,Analyzers" />
  </group>
</dependencies>

The assembly explorer shows more: image

So for .NET 7 I need to manually add the nuget packages System.Text.Json and MonoMod.Core, correct?

AqlaSolutions avatar Apr 17 '24 12:04 AqlaSolutions

We've found the cause of this exception. MonoMod doesn't support ARM architecture on MacOS. Is there something we can do to make it work there?

image image

AqlaSolutions avatar Apr 17 '24 12:04 AqlaSolutions

Contribute to the complex task of patching low level architecture in the MonoMod repository? Or simply use MacCatalyst for now?

pardeike avatar Apr 17 '24 13:04 pardeike

Excuse me, what do you mean by using MacCatalyst? I'm not a Mac user so I'm not familiar with MacCatalyst, how it can help?

Do you know any Harmony-like library that supports MacOS ARM?

AqlaSolutions avatar Apr 17 '24 14:04 AqlaSolutions

You missed my comment earlier: https://github.com/pardeike/Harmony/issues/607#issuecomment-2061115901

pardeike avatar Apr 17 '24 15:04 pardeike

Perhaps RimWorld works because Unity uses its own fork of dotnet runtime based on Mono and it may also use something like rosetta emulation. I haven't found a way to do it with dotnet.

AqlaSolutions avatar Apr 17 '24 17:04 AqlaSolutions

I close this issue as the real work has to be done in MonoMod (and is picking up a bit lately)

pardeike avatar May 08 '24 07:05 pardeike