Assembly.GetCallingAssembly Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns the Assembly of the method that invoked the currently executing method.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Shared Function GetCallingAssembly As Assembly
[SecuritySafeCriticalAttribute]
public static Assembly GetCallingAssembly()

Return Value

Type: System.Reflection.Assembly
The Assembly object of the method that invoked the currently executing method.

Remarks

If the method that calls the GetCallingAssembly method is expanded inline by the just-in-time (JIT) compiler, or if its caller is expanded inline, the assembly that is returned by GetCallingAssembly could change. For example, consider the following methods and assemblies:

  • Method M1 in assembly A1 calls GetCallingAssembly.

  • Method M2 in assembly A2 calls M1.

  • Method M3 in assembly A3 calls M2.

When M1 is not inlined, GetCallingAssembly returns A2. When M1 is inlined, GetCallingAssembly returns A3. Similarly, when M2 is not inlined, GetCallingAssembly returns A2. When M2 is inlined, GetCallingAssembly returns A3.

This effect also occurs when M1 executes as a tail call from M2, or when M2 executes as a tail call from M3. You can prevent the JIT compiler from inlining the method that calls GetCallingAssembly, by applying the MethodImplAttribute attribute with the MethodImplOptions.NoInlining flag, but there is no similar mechanism for preventing tail calls.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.