System Namespace


.NET Framework Class Library
MethodAccessException Class

Updated: July 2009

The exception that is thrown when there is an invalid attempt to access a method, such as accessing a private method from partially trusted code.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic (Declaration)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class MethodAccessException _
    Inherits MemberAccessException
Visual Basic (Usage)
Dim instance As MethodAccessException
C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class MethodAccessException : MemberAccessException
Visual C++
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class MethodAccessException : public MemberAccessException
JScript
public class MethodAccessException extends MemberAccessException
Remarks

This exception is thrown in situations such as the following:

  • A private, protected, or internal method is accessed from partially trusted code.

  • A security-critical method is accessed from partially trusted 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.

MethodAccessException uses the HRESULT COR_E_METHODACCESS, which has the value 0x80131510.

For a list of initial property values for an instance of MethodAccessException, see the MethodAccessException constructors.

Inheritance Hierarchy

System..::.Object
  System..::.Exception
    System..::.SystemException
      System..::.MemberAccessException
        System..::.MethodAccessException
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
See Also

Reference

Other Resources

Change History

Date

History

Reason

July 2009

Clarified the summary and provided additional information about when this exception is thrown.

Content bug fix.

Tags :


Community Content

Zolka
as_friend
In Managed C++, if you have #using <assembly> as_friend in a cpp file, the compiler will reach the not-public types from the other assembly. However you will get MethodAccessException during runtime if you forget adding the InternalsVisibleTo attribute with the actual assembly name to that (friend) assembly. The Exception comes right before the method is called which is using an internal type.
Tags : jit

Page view tracker