Creating a dynamic proxy for an abstract class with an internal constructor

I would like to create a dynamic proxy for a type in BCL, which is an abstract class with an internal constructor. I was a dynamic lock proxy and this fails with an exception stating that there is no parameterless constructor (there are - it is internal).

Is there a way to achieve this with a padlock? If not, then any of the other dynamic proxy frameworks can do this? This is the beginning of development, so it would be easy to change the framework.

+3


source to share


1 answer


DynamicProxy doesn't do anything that you couldn't do manually in C #. Therefore, it cannot inherit from types that it cannot construct, including types that do not have constructors available for DynamicProxy.


If you have an assembly, you can grant DynamicProxy access through AssemblyInfo.cs by adding:



[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

      

It is important to note the literal value DynamicProxyGenAssembly2

, this is a memory assembly generated by DynamicProxy and you need to grant it access.

+4


source







All Articles