I'm hitting an AccessViolationException when trying to use an interface proxy that is wrapping a third-party interface. The exception is being thrown when the emitted code writes the invocation arg array back to the original arg for a 'ref' type arg. Presumably this is because the third-party component has given an 'in' only parameter and it should not be written to.
So, I was wondering if DynamicProxy could be configured (or enhanced/hacked) to not write back some args? Maybe by configuring a custom code emitter or something...
Or thinking outside of the box, would it work to apply an [InAttribute] at runtime to the third-party interface (assuming DynamicProxy can be configured to adhere to this attribute)?
Other, maybe useful, information:
- The third-party interface doesn't use the 'in' keyword or InAttribute on the offending 'ref' arg.
- I'm trying to use interface proxies created with a target
Example code:
namespace third_party
{
public class IService
{
public int DoSomething(ref Guid guid);
}
}
namespace domain_ns
{
public class ServiceImpl : IService
{
public int DoSomething(ref Guid guid) { return 0; }
}
public static void main(string[] args)
{
...
var proxy = proxyGen.CreateInterfaceProxyWithTarget(..., new ServiceImpl(), ... );
third_party.AddService(proxy);
// Indirectly causes proxy.DoSomething() to be called.
// Throws an AccessViolationException :(
third_party.Go();
}
}