I am porting code which uses DynamicMethod
s extensively to allow for precompilation, for better cold startup performance. I noticed that DynamicMethod
s can be JITted and executed with visibility checks skipped, which allows them to access private nested types, yet normal assemblies can not (or can't they? I don't see any obvious loader option). What is the rationale behind this design decision?
I need to wave my hands a bit answering this question, CAS is forever complicated. The skipVisibility argument is relevant to trusted host applications that generate code that executes in a sandbox. In such a case, it is not appropriate to perform checks when the method is generated since the execution environment is wrong. It needs to happen when the method executes inside the sandbox. Where it is subjected to the normal CAS checks performed by the sandbox.
Setting the argument to true in fact adds a permission demand for ReflectionPermissionFlag.MemberAccess, required to have a shot at getting the method generated.
Topsy-turvy. There's some background info in this MSDN article, "Adding RestrictedMemberAccess to Sandboxed Domains" section.
© 2022 - 2024 — McMap. All rights reserved.