Is it possible to invoke internal method from a dynamic method in .NET?

只谈情不闲聊 提交于 2019-12-05 02:16:46

It will work if you skip visibility checks.

Change this line

var dm = new DynamicMethod(string.Empty, typeof(object), new Type[] { typeof(object) }, true);

See msdn: (in particular the table with all the rules.)

This is from the doco on the constructor.

restrictedSkipVisibility Type: System.Boolean true to skip JIT visibility checks on types and members accessed by the MSIL of the dynamic method, with this restriction: the trust level of the assemblies that contain those types and members must be equal to or less than the trust level of the call stack that emits the dynamic method; otherwise, false.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!