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

Invalid 'REFL041 Delegate type is not matching expected' when there is not enough info to check this #231

Open
jnm2 opened this issue Mar 25, 2020 · 0 comments

Comments

@jnm2
Copy link
Collaborator

jnm2 commented Mar 25, 2020

Assembly referenced through a binary (compiled) metadata reference:

internal interface IFoo
{
    object Bar { get; }
}

public class Foo : IFoo
{
    internal object Bar { get; }

    object IFoo.Bar => Bar;
}

Assembly with analyzer gives erroneous REFL041. This is probably because it can't see internal members, so it makes the invalid assumption that GetProperty must be targeting IFoo.Bar rather than the Foo.Bar that may or may not be there:

class C 
{
    void M()
    {
        Delegate.CreateDelegate(
            // REFL041 Delegate type is not matching expected Func<IFoo, object>
            //     ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
            typeof(Func<Foo, object>),
            typeof(Foo).GetProperty("Bar", BindingFlags.NonPublic | BindingFlags.Instance).GetMethod);
    }
}

However, this form does not give REFL041. Potentially a second bug where these two forms are not seen as equivalent:

class C 
{
    void M()
    {
        Delegate.CreateDelegate(
            typeof(Func<Foo, object>),
            typeof(Foo).GetMethod("get_Bar", BindingFlags.NonPublic | BindingFlags.Instance));
    }
}
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

No branches or pull requests

1 participant