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

Virtual property is not proxied in DynamicProxy if ProxyGenerationHook returns false for ShouldInterceptMethod #536

Closed
xumix opened this issue Sep 30, 2020 · 2 comments · Fixed by #571
Assignees
Labels
Milestone

Comments

@xumix
Copy link

xumix commented Sep 30, 2020

Expected: the property to be proxied but not intercepted.

Actual: the property is generated in the proxy but does not pass the value to the underlying instance

public class TestCacheProxyGenerationHook : AllMethodsHook
        {
            public override bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
            {
                return false;
            }
        }

public interface ITestCacheInterface
        {
            int InstanceProperty { get; set; }
        }

        public class TestClassForCache : ITestCacheInterface
        {
            public virtual int InstanceProperty { get; set; }
        }

        [Fact]
        public async Task DynamicProxy_NonIntercepted_Property_Leaked()
        {
            var instance = new TestClassForCache();
            var toProxy = instance.GetType();

            var proxyGenerationOptions = new ProxyGenerationOptions(new TestCacheProxyGenerationHook());

            var generator = new ProxyGenerator();
            var proxy = generator.CreateClassProxyWithTarget(toProxy,
                instance,
                proxyGenerationOptions);

            var accessor = (ITestCacheInterface)proxy;
            accessor.InstanceProperty = 1;

            Assert.Equal(accessor.InstanceProperty, instance.InstanceProperty); // Fails here 1 != 0
        }

@stakx
Copy link
Member

stakx commented Sep 30, 2020

I haven't run your example code yet, but on the surface, and from what I can remember, this seems very similar to #67.

@xumix
Copy link
Author

xumix commented Sep 30, 2020

I haven't run your example code yet, but on the surface, and from what I can remember, this seems very similar to #67.

True, this looks like a duplicate. Can't believe this bug lives for so long.

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.

2 participants