6

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?

Lex Li
  • 60,503
  • 9
  • 116
  • 147
cynic
  • 5,305
  • 1
  • 24
  • 40
  • 1
    -unity, as this is not related to Microsoft Unity. You might read this blog post, http://davedewinter.com/2010/11/21/tip-22-dynamicmethods-in-partial-trust/ It does require certain permissions to do so. Therefore, if you want to restrict such attempts you can. – Lex Li Apr 22 '13 at 02:07

1 Answers1

2

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536