0

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();
      }
    }
Ben Ruthig
  • 11
  • 1
  • 1
    An AccessViolationException would usually indicate DP is doing something wrong, probably best to log an issue on GitHub and share the third party library so we can look at it. There might be a way to work around this, but we've been closing a lot of APIs that shouldn't have been public because they block us making changes. – Jonathon Rossi Jul 11 '19 at 03:03
  • I don't think DP is doing anything wrong here. It should be copying "ref" args back to the caller. The problem is the third_party behaves poorly and uses a "ref" arg to pass write-protected memory and they rely on "documentation" to make sure people don't assign to it. – Ben Ruthig Jul 12 '19 at 13:37
  • Created https://github.com/castleproject/Core/issues/449 as per your request. – Ben Ruthig Jul 12 '19 at 15:06
  • 1
    Thanks, I didn't know the AccessViolationException was being thrown by the third party library and not DP when you logged this. – Jonathon Rossi Jul 15 '19 at 07:42

0 Answers0