Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is skipping visibility checks only allowed for dynamic methods?

I am porting code which uses DynamicMethods extensively to allow for precompilation, for better cold startup performance. I noticed that DynamicMethods 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?

like image 746
cynic Avatar asked Apr 04 '12 13:04

cynic


1 Answers

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.

like image 174
Hans Passant Avatar answered Sep 27 '22 22:09

Hans Passant