waoywssy / linfu

Automatically exported from code.google.com/p/linfu
0 stars 0 forks source link

Dynamic AOP proxy does not handle out arguments correctly #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a class with a method with a single out Guid parameter. Inside,
just let the method return Guid.NewGuid() inside the parameter
2. Create an IInvokeWrapper to intercept method calls
3. Create a new proxy and run this

What is the expected output? What do you see instead?
The expected output is for the proxy to execute correctly, and return the
Guid inside the out argument. What actually happens is either a memory
access exception (AccessViolationException), or a malformed Guid returned
back (ie all zeros, except perhaps for 2 bytes).

What version of the product are you using? On what operating system?
Tested with version 2.2 and DynamicProxy 1.031. Windows XP, Visual Studio
2008, .NET 3.5.

Please provide any additional information below.
A workaround is to use ref arguments instead, however these may not be
appropriate for the context of the method call.

Class:
public interface ITest { void SetGuid(out Guid value); }
public class Test : ITest { public void SetGuid(out Guid value) { value =
Guid.NewGuid(); } }
public class TestInterceptor<T> : IInvokeWrapper { ... }

//Code below
ProxyFactory factory = new ProxyFactory();
Test test = new Test();
TestInterceptor<ITest> interceptor = new TestInterceptor<ITest>(test);
ITest intTest = factory.CreateProxy<ITest>(interceptor, typeof(ITest));
Guid value;
intTest.SetGuid(out value); //Either exception here, or an invalid Guid
returned.

Original issue reported on code.google.com by nzpaulma...@gmail.com on 20 Jun 2009 at 2:01

GoogleCodeExporter commented 9 years ago
Update: I thought a workaround for this was to use ref arguments however after
further testing, these also fail with the same errors.

Original comment by nzpaulma...@gmail.com on 20 Jun 2009 at 2:06

GoogleCodeExporter commented 9 years ago
Valid workaround for those with a similar issue is to simply create an object 
(if
necessary) and return that from the method, as opposed to using out or ref 
arguments.

Original comment by nzpaulma...@gmail.com on 20 Jun 2009 at 2:15

GoogleCodeExporter commented 9 years ago

Original comment by Philip.L...@gmail.com on 7 Aug 2009 at 11:24