AccessException Method with Reflection on Windows Phone 7

While working with reflection, I recently got to the point where I wanted to access the object (in fact, a static instance of the object).

The object itself is defined by the inner class, so there is no other way to access it. Instead of directly getting a parameterized constructor, I can access a static instance using the Instance property. Using reflection, I can also get this property and set it to an instance of PropertyInfo - it is detected correctly.

However, I cannot get the value of the property via GetValue (since it is called through get_Instance () in the inner class) and sets it to the object, because I get a MethodAccessException .

The inner class is labeled SecuritySafeCritical , but I believe this should not be a problem.

Any ideas on why I am getting this exception?

0
source share
1 answer

See a MethodAccessException .

It says

This exception is thrown in situations such as:

 * 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. 

Check if the assembly is built correctly and your application has the appropriate privileges.

+2
source

Source: https://habr.com/ru/post/885748/


All Articles