What steps will reproduce the problem? 1. Create a dynamic proxy of a class which is nested 2. Confirm that works in Linfu.DynamicProxy 3. Confirm that fails in Linfu.Proxy (DP2)
What is the expected output? What do you see instead? -A proxied type is generated and an instance is returned
What version of the product are you using? On what operating system? -LinFu.Core, Version 2.2.0.19938
Please provide any additional information below. -Exception info is as follows: System.ArgumentException: The proxy factory can only generate proxies from public base classes. Parameter name: baseType.
seems to happen in the ProxyFactory.CreateProxyType(Type baseType, IEnumerable<Type> baseInterfaces) method where it checks if the type.IsPublic. Nested types do not show as IsPublic. Could change to !baseType.IsPublic && !baseType.IsNestedPublic
Comment #1
Posted on Sep 15, 2009 by Massive BirdI managed to reproduce the bug but it'll take a while for me to do in Mono.Cecil what DP1 does with System.Reflection.Emit. The problem seems to be that the Proxy Factory class needs to generate a proxy type that matches the type attribute flags of the nested base class that it's inheriting.
Here are the proxy type attributes being used in DP1:
TypeAttributes typeAttributes = TypeAttributes.AutoClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.BeforeFieldInit;
Here are the proxy type attributes being used in DP2:
var attributes = TypeAttributes.AutoClass | TypeAttributes.Class | TypeAttributes.BeforeFieldInit | TypeAttributes.Public;
Strangely enough, the DP1 version (the one that uses System.Reflection.Emit) works fine, while the version that uses Cecil cannot properly create nested proxy types. I'll have to check with Jb Evain and see what he says about it.
Status: Accepted
Labels:
Type-Defect
Priority-Medium