Skip to content

DynamicProxy emits invalid metadata for redeclared event #590

@stakx

Description

@stakx

We got a report over at devlooped/moq#1175 that appears to be caused by a bug in DynamicProxy. I've derived the following test case:

[Test]
public void Can_proxy_type_containing_redeclared_event()
{
    _ = generator.CreateInterfaceProxyWithoutTarget<IDerived>();
}

public interface IBase
{
    event Action Event;
}

public interface IDerived : IBase
{
    new event Action<bool> Event;
}

This will generate a proxy class containing two identically-named events:

.event [mscorlib]System.Action Event
{
    .addon instance void Castle.Proxies.IDerivedProxy::add_Event(class [mscorlib]System.Action)
    .removeon instance void Castle.Proxies.IDerivedProxy::remove_Event(class [mscorlib]System.Action)
}

.event class [mscorlib]System.Action`1<bool> Event
{
    .addon instance void Castle.Proxies.IDerivedProxy::add_Event(class [mscorlib]System.Action`1<bool>)
    .removeon instance void Castle.Proxies.IDerivedProxy::remove_Event(class [mscorlib]System.Action`1<bool>)
}

...which isn't legal, and PEVerify confirms that:

[MD]: Error: Event has a duplicate (token=0x14000002). [token:0x14000001]
[MD]: Error: Event has a duplicate (token=0x14000001). [token:0x14000002]

I haven't thought about possible solutions in detail, but I suspect we would need to resolve this name conflict by renaming one of the two event implementations (ideally the one for the shadowed base type's event) to e.g. Event_1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions