MethodAccessException

itisinteresting picture itisinteresting · Mar 15, 2011 · Viewed 7.5k times · Source

I have an unmanaged assebmly (encryption functionality) that a VB.NET (2.0) installer class uses for some installation diagnostics on the application server during the application installation.The problem is that whenever a method is called it throws MethodAccessException exception. When I call the method within the application itself (Windows 2.0), say any form ot other application assembly, is accepts the call as fully trusted. However,when the installer class (custom action) does the call the unmanaged assembly doesn't allow it and throws the exception. I did some research on caspol tool but still not able to grasp the code security enough to resolve the problem Thank you.

Answer

itisinteresting picture itisinteresting · Mar 27, 2011

Here is an answer I got on MSDN Forums:

This exception[MethodAccessException ] is thrown in situations such as the following:

* A private, protected, or internal method that would not be accessible from normal compiled code is accessed from partially trusted code by using reflection.
* 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.

You can see the information at the following page: http://msdn.microsoft.com/en-us/library/system.methodaccessexception(v=VS.90).aspx?appId=Dev10IDEF1&l=EN-US&k=k(APPLICATIONDEPLOYMENT);k(TargetFrameworkMoniker-

And I think your issue shoud be the second situation.

I solved the problem through reflection. Thanks, below is the link to the original answer http://social.msdn.microsoft.com/Forums/en/winformssetup/thread/de5dc1a2-c8ab-4d6a-b283-2609ed8859df

Happy coding.