Skip to content

Cannot patch default interface methods #137

@rhoot

Description

@rhoot

When a method has been implemented on an interface directly as opposed to in a class implementing that interface, there appears to be no way to patch it. Instead there is an exception raised that says "Owner can't be an array or an interface."

Repro:

interface IFoo
{
    public void FooImpl();
    public void Foo() { FooImpl(); }
}

class Foo : IFoo
{
    public void FooImpl() { Console.WriteLine("Foo"); }
}

[HarmonyPatch(typeof(IFoo), nameof(IFoo.Foo))]
static class FooPatch
{
    static void Prefix(IFoo __instance) { Console.WriteLine("Bar"); }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions