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.