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

Empty Harmony Annotations Cause ArguementException: No Target Method Found #95

Open
RobbinBob opened this issue Dec 17, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@RobbinBob
Copy link

Ran into an issue where defining a class and then using the [HarmonyPatch] attribute on that class, to mark the class or contents as a patch, then completing the attributes on the individual methods. Doing it this way causes it to throw an ArguementException error as the empty HarmonyPatch attribute is not treated as a flag and instead causes it to fail.

Incomplete code example showing a class with that attribute workflow:

[HarmonyPatch] // Seems to error here
internal static class PatchContainer
{
  [HarmonyPrefix]
  [HarmonyPatch(typeof(Type...), nameof(Method...))]
  private static bool SomeMethod_Prefix()...

This workflow should be fine as HarmonyX wiki specifies it replicates the same system Harmony uses, even pointing to documentation showcasing this workflow

@ManlyMarco
Copy link
Member

How are you patching? Does the exact same code run fine under normal Harmony?

@RobbinBob
Copy link
Author

Using .PatchAll

Yes it works fine on regular harmony

@ManlyMarco ManlyMarco added the bug Something isn't working label Dec 20, 2023
@Akilaydin
Copy link

Akilaydin commented Oct 21, 2024

Faced the same issue.

This is working

[HarmonyPatch(typeof(ItemEventTracker), nameof(ItemEventTracker.OnChestOpened))]
    public class ItemEventTracker_Patches
    {
        static void Postfix(MonoBehaviour sender, EventArgs eventArgs)
        {
            //Some logic here
        }
    }

This is not working

[HarmonyPatch(typeof(ItemEventTracker))]
    public static class ItemEventTracker_Patches
    {
        [HarmonyPatch(nameof(ItemEventTracker.OnChestOpened))]
        [HarmonyPostfix]
        static void Postfix(MonoBehaviour sender, EventArgs eventArgs)
        {
          //some logic here
 
        }
    }

Not working example throws

System.ArgumentException: No target method specified for class OriGames.SoulStonesForAll.ItemEventTracker_Patches (declaringType=GameEventTracking.ItemEventTracker, methodName =, methodType=, argumentTypes=NULL)
  at HarmonyLib.PatchProcessor.PrepareType () [0x00301] in <c855157390e846558602c247f342bc0d>:0

Tried to remove [HarmonyPostfix].
Tried to remove static keyword from the class.

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

3 participants