Why is passing visibility checks allowed only for dynamic methods?

I am porting code that DynamicMethod extensive use of to enable pre-compilation for better cold start performance. I noticed that DynamicMethod can be JITted and performed with visibility checks skipped, which allows them to access private nested types, but normal assemblies cannot (or can't they? I don't see any obvious bootloader option). What is the rationale for this design decision?

+6
source share
1 answer

I need to wave my hand, answering this question a bit, CAS is forever difficult. The skipVisibility argument refers to trusted host applications that generate code that runs in the sandbox. In this case, it is impractical to perform checks when the method is generated, since the runtime is incorrect. This should happen when the method is executed inside the sandbox. Where it undergoes the usual sandboxed CAS checks.

Setting the argument to true actually adds the permission requirement for ReflectionPermissionFlag.MemberAccess, which is required to take a snapshot when the generated method is received.

inverted. There is some background information in this MSDN article , "Adding a RestrictedMemberAccess to Sandboxed Domains Section".

+2
source

Source: https://habr.com/ru/post/912391/


All Articles