1 <Type Name="MethodAccessException" FullName="System.MethodAccessException" FullNameSP="System_MethodAccessException" Maintainer="ecma">
2 <TypeSignature Language="ILASM" Value=".class public serializable MethodAccessException extends System.MemberAccessException" />
3 <TypeSignature Language="C#" Value="public class MethodAccessException : MemberAccessException" />
4 <MemberOfLibrary>RuntimeInfrastructure</MemberOfLibrary>
6 <AssemblyName>mscorlib</AssemblyName>
7 <AssemblyPublicKey>[00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ]</AssemblyPublicKey>
8 <AssemblyVersion>1.0.5000.0</AssemblyVersion>
9 <AssemblyVersion>2.0.0.0</AssemblyVersion>
10 <AssemblyVersion>4.0.0.0</AssemblyVersion>
12 <ThreadingSafetyStatement>All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.</ThreadingSafetyStatement>
14 <BaseTypeName>System.MemberAccessException</BaseTypeName>
19 <para>Represents the error that occurs when there is an
20 attempt to access a method outside the scope in which access is permitted.</para>
24 <block subset="none" type="note">This exception is
25 thrown when the access level of a method in a class library is changed, and one
26 or more assemblies referencing the library have not been recompiled. This exception is also thrown when an attempt to invoke a
27 method via reflection fails because the caller does not have the required
32 <para>The following example demonstrates a scenario under
33 which <see cref="T:System.MethodAccessException" />
35 <para>The following code contains a class with a public method (MyMethod). This
36 class is compiled into a class library.</para>
37 <code lang="C#">using System;
38 namespace TestNameSpace
44 Console.WriteLine ("Constructing with public method.");
46 public void MyMethod ()
48 Console.WriteLine ("Calling MyMethod.");
53 <para>The following code references the class library above, and accesses
54 TestNameSpace.Class1.MyMethod. This code is compiled into an application.</para>
55 <code lang="C#">using System;
59 public static void Main()
61 Class1 test = new Class1();
66 <para>The output of the application is</para>
68 <para>Constructing with public method.</para>
69 <para>Calling MyMethod.</para>
71 <para>The code for the class library is changed and recompiled so that TestNameSpace.Class1.MyMethod is no longer public. The following code changes
72 MyMethod from public to private. </para>
73 <code lang="C#">using System;
74 namespace TestNameSpace
80 Console.WriteLine ("Constructing with private method.");
82 private void MyMethod ()
84 Console.WriteLine ("Calling MyMethod.");
89 <para>When the application is executed again without being recompiled, the output
92 <para>Unhandled Exception: System.MethodAccessException:
93 TestNameSpace.Class1.MyMethod()</para>
94 <para> at AppTest.Main()</para>
99 <Member MemberName=".ctor">
100 <MemberSignature Language="ILASM" Value="public rtspecialname specialname instance void .ctor()" />
101 <MemberSignature Language="C#" Value="public MethodAccessException ();" />
102 <MemberType>Constructor</MemberType>
107 <para>Constructs and initializes a new instance of the
108 <see cref="T:System.MethodAccessException" />
112 <para>This constructor initializes the <see cref="!:System.MethodAccessException.Message" />
113 property of the new instance to a system-supplied message that describes the
114 error, such as "Attempt to access the method failed." This message takes into
115 account the current system culture.</para>
116 <para>The <see cref="!:System.MethodAccessException.InnerException" /> property of the new instance is
117 initialized to <see langword="null" /> .</para>
120 <Excluded>0</Excluded>
122 <AssemblyVersion>1.0.5000.0</AssemblyVersion>
123 <AssemblyVersion>2.0.0.0</AssemblyVersion>
124 <AssemblyVersion>4.0.0.0</AssemblyVersion>
127 <Member MemberName=".ctor">
128 <MemberSignature Language="ILASM" Value="public rtspecialname specialname instance void .ctor(string message)" />
129 <MemberSignature Language="C#" Value="public MethodAccessException (string message);" />
130 <MemberType>Constructor</MemberType>
133 <Parameter Name="message" Type="System.String" />
136 <param name="message">A <see cref="T:System.String" /> that describes the error. The content of <paramref name="message" /> is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.</param>
138 <para>Constructs and initializes a new instance of the <see cref="T:System.MethodAccessException" /> class with
139 a specified error message.</para>
142 <para>This constructor initializes the <see cref="!:System.MethodAccessException.Message" />
143 property of the new instance using <paramref name="message" />. If <paramref name="message" /> is
144 <see langword="null" />, the <see cref="!:System.MethodAccessException.Message" /> property is initialized to the
145 system-supplied message provided by the constructor that takes no
147 <para> The <see cref="!:System.MethodAccessException.InnerException" /> property of the
148 new instance is initialized to <see langword="null" />.</para>
151 <Excluded>0</Excluded>
153 <AssemblyVersion>1.0.5000.0</AssemblyVersion>
154 <AssemblyVersion>2.0.0.0</AssemblyVersion>
155 <AssemblyVersion>4.0.0.0</AssemblyVersion>
158 <Member MemberName=".ctor">
159 <MemberSignature Language="C#" Value="protected MethodAccessException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);" />
160 <MemberType>Constructor</MemberType>
162 <Parameter Name="info" Type="System.Runtime.Serialization.SerializationInfo" />
163 <Parameter Name="context" Type="System.Runtime.Serialization.StreamingContext" />
166 <param name="info">To be added.</param>
167 <param name="context">To be added.</param>
168 <summary>To be added.</summary>
169 <remarks>To be added.</remarks>
172 <AssemblyVersion>1.0.5000.0</AssemblyVersion>
173 <AssemblyVersion>2.0.0.0</AssemblyVersion>
174 <AssemblyVersion>4.0.0.0</AssemblyVersion>
177 <Member MemberName=".ctor">
178 <MemberSignature Language="ILASM" Value="public rtspecialname specialname instance void .ctor(string message, class System.Exception inner)" />
179 <MemberSignature Language="C#" Value="public MethodAccessException (string message, Exception inner);" />
180 <MemberType>Constructor</MemberType>
183 <Parameter Name="message" Type="System.String" />
184 <Parameter Name="inner" Type="System.Exception" />
187 <param name="message">A <see cref="T:System.String" /> that describes the error. The content of <paramref name="message" /> is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.</param>
188 <param name="inner">An instance of <see cref="T:System.Exception" /> that is the cause of the current exception. If <paramref name="inner" /> is not a <see langword="null" /> reference, the current exception was raised in a catch block handling <paramref name="inner" /> .</param>
190 <para>Constructs and initializes a new instance of the <see cref="T:System.MethodAccessException" /> class with a specified error
191 message and a reference to the inner exception that is the cause of the current
195 <para>This constructor initializes the <see cref="!:System.MethodAccessException.Message" /> property of the new instance
196 using <paramref name="message" /> and the <see cref="!:System.MethodAccessException.InnerException" /> property using
197 <paramref name="inner" />. If <paramref name="message" /> is <see langword="null" />,
198 the <see cref="!:System.MethodAccessException.Message" /> property is initialized to the system-supplied message
199 provided by the constructor that takes no arguments.</para>
200 <block subset="none" type="note">For more information on inner
201 exceptions, see <see cref="P:System.Exception.InnerException" />.</block>
204 <Excluded>0</Excluded>
206 <AssemblyVersion>1.0.5000.0</AssemblyVersion>
207 <AssemblyVersion>2.0.0.0</AssemblyVersion>
208 <AssemblyVersion>4.0.0.0</AssemblyVersion>
212 <TypeExcluded>0</TypeExcluded>
215 <AttributeName>System.Runtime.InteropServices.ComVisible(true)</AttributeName>