Dynamic Assembly/Types With ReflectionPermissionFlag.RestrictedMemberAccess


Dynamic Assembly/Types With ReflectionPermissionFlag.RestrictedMemberAccess



My FlatFiles project uses System.Reflection.Emit to generate deserializers/serializers at runtime to read/write CVS files, etc. Until recently, I was able to simply use DynamicMethod passing in true for the restrictedSkipVisibility constructor parameter.


System.Reflection.Emit


DynamicMethod


true


restrictedSkipVisibility



New features I am working on require I build a class at runtime instead of a simple method. I was able to implement the new logic using AssemblyBuilder/ModuleBuilder/TypeBuilder/etc. However, I ran into issues whenever I needed to access internal project classes. For that, I added the [InternalsVisibleTo] attribute to my Assembly.cs file, giving visibility to my dynamic assembly.


AssemblyBuilder


ModuleBuilder


TypeBuilder


internal


Assembly.cs



When I look at projects like Castle.DynamicProxy.Core, I see they are relying on [InternalsVisibleTo], as well. Looking at other projects using DynamicProxy, I can see they are adding the same attribute. Anyone using these libraries must also add the attribute: example. Even then, doesn't provide access to private classes and members.


[InternalsVisibleTo]


private



From what I read online, it sounds like skipping visibility checks simply isn't possible using dynamic assemblies. Is this true? I am just looking for a confirmation.



My research also indicates that DynamicMethod's ability to skip visibility checks only works in certain environments. In other words, FlatFiles wouldn't work in a more restrictive environment (e.g., Internet). Is that true? That might be justification to force my users to add the [InternalsVisibleTo] attribute to their projects going forward.


DynamicMethod


[InternalsVisibleTo]









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV