Why is skipping visibility checks only allowed for dynamic methods?
Asked Answered
B

1

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?

Bouffe answered 4/4, 2012 at 13:32 Comment(1)
-unity, as this is not related to Microsoft Unity. You might read this blog post, davedewinter.com/2010/11/21/… It does require certain permissions to do so. Therefore, if you want to restrict such attempts you can.Mask
D
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.

Demonstration answered 10/6, 2013 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.