BepInEx.AssemblyPublicizer icon indicating copy to clipboard operation
BepInEx.AssemblyPublicizer copied to clipboard

Publicizing overridden methods causing ambiguity errors in Rider

Open DaXcess opened this issue 1 year ago • 1 comments

Publicizing an assembly which contain private methods that are overrides from a base class/interface causes ambiguity errors in certain IDE's (Rider in my case).

I remember fixing this using a custom assembly publicizer a while back by not publicizing the overridden method, and it looked something like this:

foreach (var method in type.Methods)
{
    // Detect whether or not this method is present multiple times (as an override)
    // This will only publicize the method defined by the type, and keeps the overridden method as-is
    if (!method.HasOverrides ||
        type.Methods.Count(m =>
            m.Name.ToString() == method.Name.ToString().Split(".").Last() ||
            m.Name.ToString() == method.Name.ToString()) == 1)
    {
        // Make method public
        method.Access |= MethodAttributes.Public;
        method.Access &= ~MethodAttributes.Private;
    }

    // Clear method instructions and exception handlers
    method.Body?.ExceptionHandlers?.Clear();
    method.Body?.Instructions?.Clear();
}

This however used dnlib and I have since decided to switch over to BepInEx.AssemblyPublicizer due to it being much more feature-complete

An example assembly that will generate ambiguity errors is Unity's Animation Rigging package, where the constraint data property becomes ambiguous.

Note: The assembly still compiles, and not every IDE will show the errors, however some others do and it generates a bunch of benign errors which impact DX.

DaXcess avatar Apr 11 '24 08:04 DaXcess

I can reproduce this with explicit interface implementations, but can you provide any repro code for when it happens with just overriding base class methods?

js6pak avatar Apr 21 '24 15:04 js6pak