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

Publicizing overridden methods causing ambiguity errors in Rider #13

Open
DaXcess opened this issue Apr 11, 2024 · 1 comment · May be fixed by #15
Open

Publicizing overridden methods causing ambiguity errors in Rider #13

DaXcess opened this issue Apr 11, 2024 · 1 comment · May be fixed by #15

Comments

@DaXcess
Copy link

DaXcess commented Apr 11, 2024

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.

@js6pak
Copy link
Member

js6pak commented Apr 21, 2024

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 js6pak linked a pull request Apr 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants