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

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

Closed
stakx opened this issue Jan 30, 2021 · 0 comments · Fixed by #570
Labels
Milestone

Comments

@stakx
Copy link
Member

stakx commented Jan 30, 2021

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant