Skip to content

DynamicProxy generates two modules when proceeding from a class proxy's protected method to the target #569

Closed

Description

@stakx

This is very similar to #327. (Back then we found out that DynamicProxy sometimes puts a generated invocation type in another module than the generated proxy type depending on it, causing verification failure due to the proxy type module being incomplete. This got fixed in #346.)

It appears there is another case where the same problem occurs, namely proceeding to a class proxy's target from an intercepted protected method. Because you cannot directly call protected methods from outside the target, DynamicProxy does so indirectly via a generated delegate type. Such delegate types can also end up in the wrong module:

public class Foo
{
    public string InvokeMethod()
    {
        return Method();
    }

    protected virtual string Method()
    {
        return "...";
    }
}

var builder = new PersistentProxyBuilder();
var generator = new ProxyGenerator(builder);
_ = generator.CreateClassProxyWithTarget(new Foo());
builder.SaveAssembly();

The last line triggers this exception:

System.InvalidOperationException: Both a strong-named and a weak-named assembly have been generated.

Activity

  1. added this to the v5.0.0 milestone on Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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