在处理反射时,我最近想要访问一个对象(实际上,是一个对象的静态实例)。
对象本身是由内部类定义的,因此没有其他方法来访问它。我可以通过实例属性访问静态实例,而不是直接获取参数化构造函数。在反射的帮助下,我还能够获得该属性并将其设置为PropertyInfo实例--它将被正确检测。
但是,我无法通过get_Instance()获得属性的值(因为它是通过内部类本身通过GetValue调用的),并将其设置为对象,因为我得到了一个MethodAccessException。
内部类被标记为SecuritySafeCritical,但我认为这不应该是问题所在。
对我为什么会有这个例外有什么想法?
发布于 2010-12-02 05:43:05
看看MethodAccessException。
上面写着
在以下情况下引发此异常:
* A private, protected, or internal method that would not be accessible from normal compiled code is accessed from partially trusted code by using reflection.
* A security-critical method is accessed from transparent code.
* The access level of a method in a class library has changed, and one or more assemblies that reference the library have not been recompiled.检查程序集是否已正确编译,以及应用程序是否具有适当的权限。
https://stackoverflow.com/questions/4331891
复制相似问题