Skip to content

Gendarme.Rules.Correctness.UseNoInliningWithGetCallingAssemblyRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

UseNoInliningWithGetCallingAssemblyRule

Assembly: Gendarme.Rules.Correctness
Version: 2.10

Description

This rule warns when a method call Assembly.GetCallingAssembly() from a method that is not decorated with MethodImpl(MethodImplOptions.NoInlining). Without this attribute the method could be inlined by the JIT. In this case the calling assembly would be the assembly of the caller (of the inlined method), which could be different than the assembly of the real, source-wise, caller to Assembly.GetCallingAssembly.

Examples

Bad example:

public void ShowInfo ()
{
    Console.WriteLine (Assembly.GetCallingAssembly ().Location);
}

Good example:

[MethodImpl (MethodImplOptions.NoInlining)]
public void ShowInfo ()
{
    Console.WriteLine (Assembly.GetCallingAssembly ().Location);
}

Notes

  • This rule is available since Gendarme 2.8
Clone this wiki locally