2

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.

itisinteresting
  • 125
  • 2
  • 12
  • Is the caller (the installation program) fully trusted? And what do you mean by (Windows 2.0)? Did you perhaps mean (.NET 2.0)? – Jim Mischel Mar 15 '11 at 17:11
  • It is not a CAS exception. How unmanaged code can throw a managed exception is utterly unclear from your question. – Hans Passant Mar 15 '11 at 18:00
  • 1. Yes Jim, it's .NET 2.0 How do I make the installer package fully trusted? There doesn't seem to be any settings for trust in VS 2008. – itisinteresting Mar 16 '11 at 13:17
  • 2.Hans, what I meant to say was that the assembly that throws an exeption is .NET but have no access to the code. It's referenced in the Windows app and I am referencing it in the custom action in the installet package. The installer class is also in that Windows application. The assembly performs some encryption and I suspect that because it is a security sensative operation there is some code security implemented in the code. – itisinteresting Mar 16 '11 at 13:23

1 Answers1

6

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.

itisinteresting
  • 125
  • 2
  • 12
  • Had a similar issue. Dealt with using reflection code version from Silverlight. – bizah May 06 '14 at 20:11
  • I have the same issue today after changing the accessibility of a class in a class library to public and invoking one of its method from a console application, even if I clean / rebuild the solution in Visual Studio. The reason was "trivial" (of course, after I found it): the assembly was GAC-ed, and Visual Studio (when debugging) and the application without debugging loaded the GAC-es version, which contained the non-public version of the class. So if you have the same sympthoms, check the assembly in GAC, and re-deploy the new version, if you found a former version. – pholpar Nov 07 '17 at 13:18